summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2020-12-21 10:37:09 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-12-23 10:22:35 -0500
commitf59c34b8e4322beca33e38bbb9a1df8acdf62011 (patch)
tree292d4f8c07c3ad70dbd4d1285567c863cd3d6921
parentf0ec06c76ccd6797d42736fd423adbbb238723b4 (diff)
downloadhaskell-f59c34b8e4322beca33e38bbb9a1df8acdf62011.tar.gz
Support package qualifier in Prelude import
Fix #19082, #17045
-rw-r--r--compiler/GHC/Parser/Header.hs14
-rw-r--r--testsuite/tests/parser/should_compile/T19082.hs7
-rw-r--r--testsuite/tests/parser/should_compile/all.T1
-rw-r--r--testsuite/tests/parser/should_fail/T17045.hs8
-rw-r--r--testsuite/tests/parser/should_fail/T17045.stderr5
-rw-r--r--testsuite/tests/parser/should_fail/all.T1
6 files changed, 31 insertions, 5 deletions
diff --git a/compiler/GHC/Parser/Header.hs b/compiler/GHC/Parser/Header.hs
index 4e2c297bea..5abb0497d4 100644
--- a/compiler/GHC/Parser/Header.hs
+++ b/compiler/GHC/Parser/Header.hs
@@ -129,11 +129,15 @@ mkPrelImports this_mod loc implicit_prelude import_decls
= []
| otherwise = [preludeImportDecl]
where
- explicit_prelude_import
- = notNull [ () | L _ (ImportDecl { ideclName = mod
- , ideclPkgQual = Nothing })
- <- import_decls
- , unLoc mod == pRELUDE_NAME ]
+ explicit_prelude_import = any is_prelude_import import_decls
+
+ is_prelude_import (L _ decl) =
+ unLoc (ideclName decl) == pRELUDE_NAME
+ -- allow explicit "base" package qualifier (#19082, #17045)
+ && case ideclPkgQual decl of
+ Nothing -> True
+ Just b -> sl_fs b == unitIdFS baseUnitId
+
preludeImportDecl :: LImportDecl GhcPs
preludeImportDecl
diff --git a/testsuite/tests/parser/should_compile/T19082.hs b/testsuite/tests/parser/should_compile/T19082.hs
new file mode 100644
index 0000000000..bd5c4f048f
--- /dev/null
+++ b/testsuite/tests/parser/should_compile/T19082.hs
@@ -0,0 +1,7 @@
+{-# LANGUAGE PackageImports #-}
+
+module Foo (String) where
+
+import "base" Prelude hiding (String)
+
+data String = String
diff --git a/testsuite/tests/parser/should_compile/all.T b/testsuite/tests/parser/should_compile/all.T
index 0f63299386..4aa6d17ec0 100644
--- a/testsuite/tests/parser/should_compile/all.T
+++ b/testsuite/tests/parser/should_compile/all.T
@@ -173,3 +173,4 @@ test('T18130', normal, compile, [''])
test('T18834a', normal, compile, [''])
test('T18834b', normal, compile, [''])
test('T12862', normal, compile, [''])
+test('T19082', normal, compile, [''])
diff --git a/testsuite/tests/parser/should_fail/T17045.hs b/testsuite/tests/parser/should_fail/T17045.hs
new file mode 100644
index 0000000000..7b3fb01f4d
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/T17045.hs
@@ -0,0 +1,8 @@
+{-# LANGUAGE PackageImports #-}
+
+module Bug where
+
+import "base" Prelude (zip)
+
+wobbly :: String
+wobbly = "hello"
diff --git a/testsuite/tests/parser/should_fail/T17045.stderr b/testsuite/tests/parser/should_fail/T17045.stderr
new file mode 100644
index 0000000000..fdcf4422ea
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/T17045.stderr
@@ -0,0 +1,5 @@
+
+T17045.hs:7:11: error:
+ Not in scope: type constructor or class ‘String’
+ Perhaps you want to add ‘String’ to the import list
+ in the import of ‘Prelude’ (T17045.hs:5:1-27).
diff --git a/testsuite/tests/parser/should_fail/all.T b/testsuite/tests/parser/should_fail/all.T
index f79c14fdc1..88a37ec2ba 100644
--- a/testsuite/tests/parser/should_fail/all.T
+++ b/testsuite/tests/parser/should_fail/all.T
@@ -174,3 +174,4 @@ test('T18251d', normal, compile_fail, [''])
test('T18251e', normal, compile_fail, [''])
test('T18251f', normal, compile_fail, [''])
test('T12446', normal, compile_fail, [''])
+test('T17045', normal, compile_fail, [''])