Skip to content

GHC accepts import of private data constructor if it has the same name as the type

$ cat A.hs B.hs
module A (T) where

data T = T

module B where

import A (T(T))

ghci-7.8.2 accepts module B, whereas ghci-7.6.3 and ghci-7.4.2 say:

B.hs:3:11: Module `A' does not export `T(T)'

For this bug to happen it is important, that the data constructor has the same name as the type. I.e. if you rename the data constructor to, say, Cons, then ghci-7.8.2 will emit the same error as earlier versions. The bug is not dramatic, since if you try to actually use the imported data constructor then ghc will say

B.hs:20:5:
    Not in scope: data constructor ‘T’

However this error message is very confusing, because it suggests that T is not in scope although you imported it correctly.

Trac metadata
Trac field Value
Version 7.8.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information