Ticket #7167 (closed bug: fixed)

Opened 9 months ago

Last modified 9 months ago

Make it a warning (not error) to hide an import that isn't exported

Reported by: simonpj Owned by: pcapriotti
Priority: highest Milestone: 7.6.1
Component: Compiler Version: 7.4.2
Keywords: Cc: jwlato@…, conrad@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: rename/should_compile/T7167 Blocked By:
Blocking: Related Tickets:

Description

We often see build failures like

    Module `Prelude' does not export `catch'

elicited by an import statement

  import Prelude hiding( catch )

John Lato and others suggest making this a warning, not an error. Simon and I agree and we propose to do this for GHC 7.6, thus:

  • Warn, rather than error, when a hiding clause mentions something that the module does not export.
  • Suppress with warning with -fno-warn-dodgy-imports, an existing warning-suppression flag.
  • Document the change, in the -fwarn-docugy-imports flag, and the release notes.

We propose to make this change without a language extension. Doing so is technically wrong, since H2010 says it's an error to mention something in hiding that isn't exported, but it seems too heavyweight to make a language extension just for this; and in any case it would have to be on by default to be any use in practice.

Paolo, can you do all this?

  • The relevant function is RnNames.filterImports.
  • I suggest you make lookup_ie return TcRn [(LIE Name,AvailInfo)] rather than the MaybeErr ... that it currently returns.
  • The want_hiding flag is True if this is a hiding clause; in that case bad_ie should warn (unless the warning is suppressed) rather than error.

Change History

Changed 9 months ago by simonpj

  • owner set to pcapriotti

Changed 9 months ago by jwlato

  • cc jwlato@… added

Changed 9 months ago by conrad

  • cc conrad@… added

Changed 9 months ago by p.capriotti@…

commit 3d7c81a4be00a6d72b321b4811ab316ea3301a60

Author: Paolo Capriotti <p.capriotti@gmail.com>
Date:   Thu Aug 23 12:54:45 2012 +0100

    Make badImportItem into a warning (#7167)
    
    Also fix a bug where a dodgy import warning was emitted for data
    families with a single constructor.

 compiler/rename/RnNames.lhs |  191 ++++++++++++++++++++++++++-----------------
 1 files changed, 116 insertions(+), 75 deletions(-)

Changed 9 months ago by pcapriotti

  • status changed from new to merge
  • testcase set to rename/should_compile/T7167

Documentation patch here:

commit 4eb02c17fc814275a4294afe5c9f38eff8c6a489
Author: Paolo Capriotti <p.capriotti@gmail.com>
Date:   Sat Aug 25 20:33:36 2012 +0100

    Update documentation for -fwarn-dodgy-imports.

The bug in data family imports mentioned in the commit above is as follows. Given a module DodgyA:

{-# LANGUAGE TypeFamilies #-}

module DodgyA(C(..), X(..)) where

class C a where
  data X a

instance C Int where
  data X Int = X1 Bool

the following import triggered a "dodgy import" warning:

import DodgyA (X(..))

even though the X1 constructor is exported. This has been fixed by the refactoring, and is now checked by the testcase rename/should_compile/dodgy.

Changed 9 months ago by mgsloan1

I was about to submit this bug report - that exact "import Prelude hiding (catch)" crops up in XMonad/Core.hs - and I've run into it in other contexts in the past (hiding trace from Diagrams.Prelude)

Glad it's being fixed!

Changed 9 months ago by pcapriotti

  • status changed from merge to closed
  • resolution set to fixed

Merged as 68fd5dcd5118816e03d6c5e23533faa298d34834.

Note: See TracTickets for help on using tickets.