Skip to content

TH's mkName fails to check namespace for built-in syntax

Consider

data T = FU | FUN

expr1 = $( conE (mkName "FU") )
expr2 = $( conE (mkName "FUN") )

expr1 compiles just fine. But expr2 fails with

    • Illegal term-level use of the type constructor ‘FUN’
        imported from ‘GHC.Exts’ at Scratch.hs:35:1-15
        (and originally defined in ‘GHC.Prim’)
    • In the expression: FUN
      In an equation for ‘expr2’: expr2 = (FUN)
   |
43 | expr2 = $( conE (mkName "FUN") )
   |      

This would appear to be because isBuiltInOcc_maybe does not check for namespace in some cases.

Another way to make this happen:

expr3 = $( [| FU |] )
expr4 = $( [| FUN |] )

expr3 is accepted, while expr4 runs into trouble. This goes via a different code path, but ends up in isBuiltInOcc_maybe all the same.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information