Skip to content

Missing String import with position tokens in Haskell backend #368

@MrQubo

Description

@MrQubo

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

|| hasIdentLike && tokenText == StringToken && s == "String")
hasIdentLike is used, which only includes non-position tokens as described in this comment

bnfc/source/src/BNFC/CF.hs

Lines 758 to 759 in 94cc080

-- Excludes position tokens.
hasIdentLikeTokens :: CFG g -> Bool
.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions