Skip to content

Ambiguity when exporting a data constructor despite qualification

$ cat A.hs
module A where

data T = Cons

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

import qualified A

data T = T

$ ghc-8.2.0.20170422 -Wall B.hs
[2 of 2] Compiling B                ( B.hs, B.o ) [A changed]

B.hs:1:11: error:
    • Ambiguous occurrence ‘T’
      It could refer to either ‘A.T’,
                               imported qualified from ‘A’ at B.hs:3:1-18
                            or ‘T’, defined at B.hs:5:1
    • In the export: T(T)
  |
1 | module B (T(T)) where
  |           ^^^^

There should be no ambiguity, because there is only one data constructor named T. Even if A.T's data constructor would also be called T there would be no ambiguity because A is imported with qualification. The problem does not appear, if B.T's data constructor is named Cons.

Trac metadata
Trac field Value
Version 8.2.1-rc2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Parser)
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