Export item suggests constructors/methods [GHC-75356]
Flag: -Wdodgy-imports
Enabled by: -Wextra
When exporting identifiers from a module, all in-scope constructors (for a type) or the in-scope methods (for a typeclass) can also be exported with the T(..)
syntax. However, if T
does not have in-scope constructors (the type is being re-exported and does not have its constructors imported) or it has no constructors - then this export item suggests that the programmer intended for T
to have in-scope constructors/methods when it has none.
Examples
Export item suggests constructors/methods
When re-exporting TypeWithoutVisibleCtrs
originally imported from module HiddenCtrs
and then re-exported in module DodgyExports
, the export list item suggests that this type has associated in-scope constructor(s). However it does not (the constructors are out of scope). The same is true of TypeWithNoCtrs
; the export item suggests it has constructors whereas it has none (either in or out of scope).
The solution is to export the type abstractly (without (..)
).
Error Message
DodgyExports.hs:1:22: warning: [-Wdodgy-exports] [GHC-75356]
The export item ‘TypeWithoutVisibleCtrs(..)’ suggests that
‘TypeWithoutVisibleCtrs’ has (in-scope) constructors or class methods,
but it has none
|
1 | module DodgyExports (TypeWithoutVisibleCtrs(..), TypeWithNoCtrs(..)) where
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
DodgyExports.hs:1:50: warning: [-Wdodgy-exports] [GHC-75356]
The export item ‘TypeWithNoCtrs(..)’ suggests that
‘TypeWithNoCtrs’ has (in-scope) constructors or class methods,
but it has none
|
1 | module DodgyExports (TypeWithoutVisibleCtrs(..), TypeWithNoCtrs(..)) where
| ^^^^^^^^^^^^^^^^^^
DodgyExports.hs
module DodgyExports (TypeWithoutVisibleCtrs(..), TypeWithNoCtrs(..)) where
import HiddenCtrs
data TypeWithNoCtrs
module DodgyExports (TypeWithoutVisibleCtrs, TypeWithNoCtrs) where
import HiddenCtrs
data TypeWithNoCtrs
HiddenCtrs.hs
module HiddenCtrs (TypeWithoutVisibleCtrs) where
data TypeWithoutVisibleCtrs = Ctr1 Int | Ctr2 | Ctr3 Bool Bool
module HiddenCtrs (TypeWithoutVisibleCtrs) where
data TypeWithoutVisibleCtrs = Ctr1 Int | Ctr2 | Ctr3 Bool Bool