Lexer: Alternate Layout Rule injects actual not virtual braces
authorAlan Zimmerman <alan.zimm@gmail.com>
Sun, 3 Feb 2019 08:27:42 +0000 (10:27 +0200)
committerBen Gamari <ben@smart-cactus.org>
Wed, 20 Feb 2019 19:28:55 +0000 (14:28 -0500)
commite0375ba980fd5639d23a29575efb00c30d97c743
tree72500635b779f87213ecc9eacd29f32ede771648
parenta7c1f9bb17933816f7d56c9ad016a2c26ad5c8a8
Lexer: Alternate Layout Rule injects actual not virtual braces

When the alternate layout rule is activated via a pragma, it injects
tokens for { and } to make sure that the source is parsed properly.

But it injects ITocurly and ITccurly, rather than their virtual
counterparts ITvocurly and ITvccurly.

This causes problems for ghc-exactprint, which tries to print these.

Likewise, any injected ITsemi should have a zero-width SrcSpan.

Test case (the existing T13087.hs)

    {-# LANGUAGE AlternativeLayoutRule #-}
    {-# LANGUAGE LambdaCase            #-}

    isOne :: Int -> Bool
    isOne = \case 1 -> True
                  _ -> False

    main = return ()

Closes #16279

(cherry picked from commit c1cf2693d6efddeeeb813cd8995a1be136800d17)
compiler/parser/Lexer.x
libraries/Cabal
libraries/transformers
testsuite/tests/ghc-api/annotations/Makefile
testsuite/tests/ghc-api/annotations/T16279.stdout [new file with mode: 0644]
testsuite/tests/ghc-api/annotations/Test16279.hs [new file with mode: 0644]
testsuite/tests/ghc-api/annotations/all.T
utils/haddock
utils/hsc2hs