Ticket #5592 (closed bug: fixed)

Opened 19 months ago

Last modified 19 months ago

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 Difficulty:
Test Case: rename/should_compile/T5592 Blocked By:
Blocking: Related Tickets:

Description

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.

Change History

Changed 19 months ago by simonpj@…

commit 0f6ab7766e8cd131ed50c76f3a381ee690c3a010

Author: Simon Peyton Jones <simonpj@microsoft.com>
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(-)

Changed 19 months ago by simonpj

  • status changed from new to closed
  • testcase set to rename/should_compile/T5592
  • resolution set to fixed

Excellent point thank you. Fixed by the above patch.

Simon

Note: See TracTickets for help on using tickets.