Admin message

Due to a large amount of spam we do not allow new users to create repositories, they are "external" users. If you are a new user and want to create a repository, for example for forking GHC, open a new issue on ghc/ghc using the "get-verified" issue template

Dodgy import breaks a hiding clause
## Summary **Variation 1**. Consider this correct program consisting of two modules: ```haskell module T25984a_helper where data H = A | B | C ``` ```haskell module T25984a where import T25984a_helper hiding (H(A,B,C)) data T = A | B | C t :: T t = A ``` In the definition `t = A`, it is important that only one of the `A`s is in scope, otherwise we'd get an ambiguity error. Hence the `hiding` clause. **Variation 2**. Now let us see what happens when we remove one of `H`'s data constructors: ```haskell module T25984b_helper where data H = A | B -- no C ``` ```haskell module T25984b where import T25984b_helper hiding (H(A,B,C)) data T = A | B | C t :: T t = A ``` This time we do get an ambiguity error! ``` T25984b.hs:8:5: error: [GHC-87543] Ambiguous occurrence ‘A’. It could refer to either ‘T25984b_helper.A’, imported from ‘T25984b_helper’ at T25984b.hs:3:1-39 (and originally defined at T25984b_helper.hs:3:10), or ‘T25984b.A’, defined at T25984b.hs:5:10. | 8 | t = A | ^ ``` But should we really get this error? I am going to argue that no, we shouldn't. Please consider: **Variation 3**, with `t` commented out ```haskell module T25984c_helper where data H = A | B -- no C ``` ```haskell module T25984c where import T25984c_helper hiding (H(A,B,C)) data T = A | B | C -- t :: T -- t = A ``` This time the program is accepted with a warning: ``` T25984c.hs:3:31: warning: [GHC-56449] [-Wdodgy-imports] In the import of ‘T25984c_helper’: an item called ‘H’ is exported, but it is a type. | 3 | import T25984c_helper hiding (H(A,B,C)) | ^^^^^^^^ ``` So the import statement is OK. It is not a problem to import a non-existent data constructor `C`. With `-Wdodgy-imports` it results in a warning, but that's a warning, not an error. The actual problem is that when GHC discovers that this import is dodgy (i.e. hides non-existent items), it discards it completely. So the `hiding` clause no longer works, even the non-dodgy parts of it. Here's an informal spec that I propose instead: a dodgy import should behave as if all its dodgy items were removed ```diff - import T25984b_helper hiding (H(A,B,C)) + import T25984b_helper hiding (H(A,B)) ``` This way Variation 2 would be accepted. ## Steps to reproduce Compile **Variation 2** and observe the error message. ## Expected behavior No error message. ## Environment * GHC version used: GHC 9.12.1, HEAD
issue