Incorrect "redundant import" warning
Record fields are incorrectly deemed "redundant" by GHC in at least some circumstances. This causes a confusing warning when -Wall is on.
Given the following module,
module MyRecord where
data MyRecord = MyRecord { field :: String } deriving (Show)
the following program's meaning will change depending on whether or not "field" is imported:
{-# LANGUAGE RecordWildCards #-}
import qualified MyRecord as MR (MyRecord(MyRecord))
main = do
let field = "Hello, world!"
rec = MR.MyRecord {..}
print rec
The program as written will crash, because the record wildcard will not use the 'field' variable, since the 'field' record label is not imported. A warning is correctly issued regarding the missing field.
However, if the user adds an import for 'field',
import qualified MyRecord as MR (MyRecord(MyRecord, field))
GHC will issue a warning:
Main.hs:3:1:
Warning: The import of `MR.field'
from module `MyRecord' is redundant
However, adding the import of 'field' causes the record wildcard to have access to the 'field' label, so the program does not crash.
Since the import changes the meaning of the program, it shouldn't be considered redundant.
Trac metadata
Trac field | Value |
---|---|
Version | 7.2.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |