LINE pragma behaviour

Ben Gamari ben at smart-cactus.org
Tue Nov 23 20:13:27 UTC 2021


"Alan & Kim Zimmerman" <alan.zimm at gmail.com> writes:

> I am working through some ghc-exactprint test cases with GHC 9.2.1 and came
> across an oddity.
>
> If I parse some source with
>
> {-# LINE 93 "Foo.chs" #-}
>
> on line five, it shows up in the ParseSource as
>
> (L
>   (Anchor
>    { LINE:5:1-25 }
>    (UnchangedAnchor))
>   (EpaComment
>    (EpaLineComment
>     "{-# LINE 93 \"Foo.chs\" #-}")
>    { LINE:5:1-25 }))
>
> and the following item locations are unchanged.
>
> The effect seems to be to change the name of the file in the RealSrcSpan to
> "LINE", but just for that line, and no other effect.
>
> Is this expected?
>
It sounds wrong to me, although it is surprising that there aren't any
tests covering this.

A quick search of the lexer reveals that GHC.Parser.Lexer.mkParserOpts
takes an argument which dictates whether LINE and COLUMN pragmas update
the lexer's source location or are instead just emitted in the lexeme
stream.

That being said, `GHC.Driver.Config.Parser.initParserOpts` seems to pass
`True` here, which should update the source location.

Were you testing with GHC or are you using the GHC API?

Cheers,

- Ben
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20211123/637c1717/attachment.sig>


More information about the ghc-devs mailing list