Take subordinate 'type' specifiers into account
This patch fixes multiple bugs (#22581, #25983, #25984, #25991) in name resolution of subordinate import lists. Bug #22581 ---------- In subordinate import lists, the use of the `type` namespace specifier used to be ignored. For example, this import statement was incorrectly accepted: import Prelude (Bool(type True)) Now it results in an error message: <interactive>:2:17: error: [GHC-51433] In the import of ‘Prelude’: a data type called ‘Bool’ is exported, but its subordinate item ‘True’ is not in the type namespace. Bug #25983 ---------- In subordinate import lists within a `hiding` clause, non-existent items led to a poor warning message with -Wdodgy-imports. Consider: import Prelude hiding (Bool(X)) The warning message for this import statement used to misreport the cause of the problem: <interactive>:3:24: warning: [GHC-56449] [-Wdodgy-imports] In the import of ‘Prelude’: an item called ‘Bool’ is exported, but it is a type. Now the warning message is correct: <interactive>:2:24: warning: [GHC-10237] [-Wdodgy-imports] In the import of ‘Prelude’: a data type called ‘Bool’ is exported, but it does not export any constructors or record fields called ‘X’. Bug #25984 ---------- In subordinate import lists within a `hiding` clause, non-existent items resulted in the entire import declaration being discarded. For example, this program was incorrectly accepted: import Prelude hiding (Bool(True,X)) t = True Now it results in an error message: <interactive>:2:5: error: [GHC-88464] Data constructor not in scope: True Bug #25991 ---------- In subordinate import lists, it was not possible to refer to a class method if there was an associated type of the same name: module M_helper where class C a b where type a # b (#) :: a -> b -> () module M where import M_helper (C((#))) This import declaration failed with: M.hs:2:28: error: [GHC-10237] In the import of ‘M_helper’: an item called ‘C’ is exported, but it does not export any children (constructors, class methods or field names) called ‘#’. Now it is accepted. Summary ------- The changes required to fix these bugs are almost entirely confined to GHC.Rename.Names. Other than that, there is a new error constructor BadImportNonTypeSubordinates with error code [GHC-51433]. Test cases: T22581a T22581b T22581c T22581d T25983a T25983b T25983c T25983d T25983e T25983f T25983g T25984a T25984b T25991a T25991b1 T25991b2
Showing
- compiler/GHC/Rename/Names.hs 159 additions, 83 deletionscompiler/GHC/Rename/Names.hs
- compiler/GHC/Tc/Errors/Ppr.hs 34 additions, 6 deletionscompiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Errors/Types.hs 3 additions, 1 deletioncompiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Types/Error/Codes.hs 1 addition, 0 deletionscompiler/GHC/Types/Error/Codes.hs
- docs/users_guide/9.14.1-notes.rst 3 additions, 0 deletionsdocs/users_guide/9.14.1-notes.rst
- docs/users_guide/exts/explicit_namespaces.rst 14 additions, 0 deletionsdocs/users_guide/exts/explicit_namespaces.rst
- testsuite/tests/driver/RecompExports/RecompExports1.stderr 2 additions, 2 deletionstestsuite/tests/driver/RecompExports/RecompExports1.stderr
- testsuite/tests/driver/RecompExports/RecompExports4.stderr 4 additions, 4 deletionstestsuite/tests/driver/RecompExports/RecompExports4.stderr
- testsuite/tests/module/T21826.stderr 5 additions, 5 deletionstestsuite/tests/module/T21826.stderr
- testsuite/tests/module/mod81.stderr 3 additions, 3 deletionstestsuite/tests/module/mod81.stderr
- testsuite/tests/module/mod91.stderr 3 additions, 3 deletionstestsuite/tests/module/mod91.stderr
- testsuite/tests/rename/should_compile/T22581c.hs 13 additions, 0 deletionstestsuite/tests/rename/should_compile/T22581c.hs
- testsuite/tests/rename/should_compile/T22581c_helper.hs 10 additions, 0 deletionstestsuite/tests/rename/should_compile/T22581c_helper.hs
- testsuite/tests/rename/should_compile/T22581d.script 2 additions, 0 deletionstestsuite/tests/rename/should_compile/T22581d.script
- testsuite/tests/rename/should_compile/T22581d.stdout 5 additions, 0 deletionstestsuite/tests/rename/should_compile/T22581d.stdout
- testsuite/tests/rename/should_compile/T25983a.hs 5 additions, 0 deletionstestsuite/tests/rename/should_compile/T25983a.hs
- testsuite/tests/rename/should_compile/T25983a.stderr 5 additions, 0 deletionstestsuite/tests/rename/should_compile/T25983a.stderr
- testsuite/tests/rename/should_compile/T25983b.hs 5 additions, 0 deletionstestsuite/tests/rename/should_compile/T25983b.hs
- testsuite/tests/rename/should_compile/T25983b.stderr 5 additions, 0 deletionstestsuite/tests/rename/should_compile/T25983b.stderr
- testsuite/tests/rename/should_compile/T25983c.hs 5 additions, 0 deletionstestsuite/tests/rename/should_compile/T25983c.hs
Loading
Please register or sign in to comment