Skip to content

Detect version control conflict markers in the lexer (#22412)

Lawton Nichols requested to merge lawtonnichols/ghc:T22412 into master

Adds normal and Perforce-style conflict marker detection capabilities to the lexer, using clang's conflict marker detection as a reference.

Sample file:

module Foo where
 
foo :: Int -> Int
<<<<<<< HEAD
foo x = x + 42
=======
foo x = x * 42
>>>>>>> branch

bar :: Int -> Int
<<<<<<< HEAD
bar y = y + 42
=======
bar y = y * 42
>>>>>>> branch

-- unrelated lexer error:
baz = "string that does not end

Previously, we emitted the following lexer errors:

asdf.hs:4:1: error: parse error on input ‘<<<<<<<’
  |
4 | <<<<<<< HEAD
  | ^^^^^^^

Now, we emit:

asdf.hs:4:1: error: [GHC-30152]
    Version control conflict marker in file
  |
4 | <<<<<<< HEAD
  | ^^^^^^^

asdf.hs:11:1: error: [GHC-30152]
    Version control conflict marker in file
   |
11 | <<<<<<< HEAD
   | ^^^^^^^

asdf.hs:18:32: error: [GHC-21231]
    lexical error in string/character literal at character '\n'
   |
18 | baz = "string that does not end
   | ^ 

Lexing the conflicting code does not seem fruitful—it is unlikely that the committed code between the conflict markers will contain non-spurious lexer errors. For this reason, I have the lexer simply skip until the end of the closing conflict marker before continuing to lex more tokens.

Closes #22412.

Merge request reports