Opened 6 years ago

Closed 6 years ago

#5592 closed bug (fixed)

Incorrect "redundant import" warning

Reported by: ryantrinkle Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.2.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect warning at compile-time Test Case: rename/should_compile/T5592
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


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:

    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.

Change History (2)

comment:1 Changed 6 years ago by simonpj@…

commit 0f6ab7766e8cd131ed50c76f3a381ee690c3a010

Author: Simon Peyton Jones <>
Date:   Wed Nov 2 10:18:00 2011 +0000

    Fix Trac #5592: unused-import warnings with dot-dot notation
    A subtle interaction between two complicate features!

 compiler/rename/RnEnv.lhs |   20 +++++++++++++-----
 compiler/rename/RnPat.lhs |   48 +++++++++++++++++++++++++-------------------
 2 files changed, 41 insertions(+), 27 deletions(-)

comment:2 Changed 6 years ago by simonpj

Resolution: fixed
Status: newclosed
Test Case: rename/should_compile/T5592

Excellent point thank you. Fixed by the above patch.


Note: See TracTickets for help on using tickets.