Bidirectional formatting warning [GHC-03272]

Flag: -Wunicode-bidirectional-format-characters
Enabled by default

This warning is emitted when a file contains one of the following Unicode characters:

Character Name
'\x202a' U+202A LEFT-TO-RIGHT EMBEDDING (LRE)
'\x202b' U+202B RIGHT-TO-LEFT EMBEDDING (RLE)
'\x202c' U+202C POP DIRECTIONAL FORMATTING (PDF)
'\x202d' U+202D LEFT-TO-RIGHT OVERRIDE (LRO)
'\x202e' U+202E RIGHT-TO-LEFT OVERRIDE (RLO)
'\x2066' U+2066 LEFT-TO-RIGHT ISOLATE (LRI)
'\x2067' U+2067 RIGHT-TO-LEFT ISOLATE (RLI)
'\x2068' U+2068 FIRST STRONG ISOLATE (FSI)
'\x2069' U+2069 POP DIRECTIONAL ISOLATE (PDI)

These characters can lead to misleading text formatting in some editors due to a lack of consistent support for Unicode bidirectional text.

Examples

Bidirectional formatting in a comment

Message

BiDi.hs:3:26: warning: [-Wunicode-bidirectional-format-characters] [GHC-03272]
    A unicode bidirectional formatting character (U+202E RIGHT-TO-LEFT OVERRIDE (RLO))
    was found at offset 44 in the file
    along with further bidirectional formatting characters at offset 65: U+202C POP DIRECTIONAL FORMATTING (PDF)
    Bidirectional formatting characters may be rendered misleadingly in certain editors
  |
3 | -- This comment contains ‮bidirectional format‬ chars
  |                          ^

Explanation

The phrase “bidirectional format” is surrounded by U+202E RIGHT-TO-LEFT OVERRIDE (RLO) and U+202C POP DIRECTIONAL FORMATTING (PDF) characters in the code that causes the warning to be emitted. In software with good support for bidirectional text, the resulting comment reads “This comment contains tamrof lanoitceridib chars”. When bidirectional layout is intended, the warning should be disabled; if bidirectional layout is not intended, the control characters should be removed.

BiDi.hs
Before
module BiDi where

-- This comment contains ‮bidirectional format‬ chars
After
module BiDi where

-- This comment no longer contains bidirectional format chars