BNFC / bnfc

BNF Converter
http://bnfc.digitalgrammars.com/
587 stars 165 forks source link

Missing String import with position tokens in Haskell backend #368

Closed MrQubo closed 3 years ago

MrQubo commented 3 years ago

Minimal example:

position token Tok '_' ;
Entrypoint . Entrypoint ::= Tok ;

Save this under bug.cf in some temporary directory, run bnfc bug.cf, run runhaskell TestBug.hs. This is the error:

AbsBug.hs:18:36: error:
    Not in scope: type constructor or class ‘String’
   |
18 | newtype Tok = Tok ((C.Int, C.Int), String)
   |                                    ^^^^^^

I've only confirmed this bug with 2.9.1 release (from stackage) and not with master, but after quick look into code it seems like this wasn't fixed.

The cause of this bug is probably that here https://github.com/BNFC/bnfc/blob/94cc0809661ccd415a6e8f525cc56d6443b546c3/source/src/BNFC/Backend/Haskell/CFtoAbstract.hs#L154 hasIdentLike is used, which only includes non-position tokens as described in this comment https://github.com/BNFC/bnfc/blob/94cc0809661ccd415a6e8f525cc56d6443b546c3/source/src/BNFC/CF.hs#L758-L759.

andreasabel commented 3 years ago

Thanks for the report, @MrQubo, I can confirm that this is a regression in 2.9.1.