summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarrieMY <carrie.xmy@gmail.com>2021-10-12 19:25:49 +0800
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-11-05 05:30:13 -0400
commitf0b920d1613db43925c01f02b0f550e29b11a86b (patch)
treee940dd971bc311117ba66d2f35426bd85efb9c66
parent086e288c6bb121581debd9308a8c2278f294e35a (diff)
downloadhaskell-f0b920d1613db43925c01f02b0f550e29b11a86b.tar.gz
Fix deferOutOfScopeVariables for qualified #20472
-rw-r--r--compiler/GHC/Rename/Expr.hs14
-rw-r--r--testsuite/tests/rename/should_compile/T20472.hs8
-rw-r--r--testsuite/tests/rename/should_compile/T20472.stderr9
-rw-r--r--testsuite/tests/rename/should_compile/all.T1
4 files changed, 22 insertions, 10 deletions
diff --git a/compiler/GHC/Rename/Expr.hs b/compiler/GHC/Rename/Expr.hs
index d02d04515e..53d9c6fa32 100644
--- a/compiler/GHC/Rename/Expr.hs
+++ b/compiler/GHC/Rename/Expr.hs
@@ -207,16 +207,10 @@ finishHsVar (L l name)
; return (HsVar noExtField (L (la2na l) name), unitFV name) }
rnUnboundVar :: RdrName -> RnM (HsExpr GhcRn, FreeVars)
-rnUnboundVar v =
- if isUnqual v
- then -- Treat this as a "hole"
- -- Do not fail right now; instead, return HsUnboundVar
- -- and let the type checker report the error
- return (HsUnboundVar noExtField (rdrNameOcc v), emptyFVs)
-
- else -- Fail immediately (qualified name)
- do { n <- reportUnboundName v
- ; return (HsVar noExtField (noLocA n), emptyFVs) }
+rnUnboundVar v = do
+ deferOutofScopeVariables <- goptM Opt_DeferOutOfScopeVariables
+ unless (isUnqual v || deferOutofScopeVariables) (reportUnboundName v >> return ())
+ return (HsUnboundVar noExtField (rdrNameOcc v), emptyFVs)
rnExpr (HsVar _ (L l v))
= do { dflags <- getDynFlags
diff --git a/testsuite/tests/rename/should_compile/T20472.hs b/testsuite/tests/rename/should_compile/T20472.hs
new file mode 100644
index 0000000000..6d4d2b4d24
--- /dev/null
+++ b/testsuite/tests/rename/should_compile/T20472.hs
@@ -0,0 +1,8 @@
+{-# OPTIONS_GHC -fdefer-out-of-scope-variables #-}
+
+module T20472 where
+
+a = nonexistent
+b = Prelude.nonexistent
+c = True
+d = Nonexistent.x
diff --git a/testsuite/tests/rename/should_compile/T20472.stderr b/testsuite/tests/rename/should_compile/T20472.stderr
new file mode 100644
index 0000000000..0b26c5b480
--- /dev/null
+++ b/testsuite/tests/rename/should_compile/T20472.stderr
@@ -0,0 +1,9 @@
+
+T20472.hs:5:5: warning: [-Wdeferred-out-of-scope-variables (in -Wdefault)]
+ Variable not in scope: nonexistent
+
+T20472.hs:6:5: warning: [-Wdeferred-out-of-scope-variables (in -Wdefault)]
+ Variable not in scope: nonexistent
+
+T20472.hs:8:5: warning: [-Wdeferred-out-of-scope-variables (in -Wdefault)]
+ Variable not in scope: x
diff --git a/testsuite/tests/rename/should_compile/all.T b/testsuite/tests/rename/should_compile/all.T
index 5260145edd..2148470c66 100644
--- a/testsuite/tests/rename/should_compile/all.T
+++ b/testsuite/tests/rename/should_compile/all.T
@@ -176,3 +176,4 @@ test('T18264', [], makefile_test, ['T18264'])
test('T18302', expect_broken(18302), compile, [''])
test('T17853', [], multimod_compile, ['T17853', '-v0'])
test('T19966', expect_broken(19966), compile, ['-fdefer-out-of-scope-variables'])
+test('T20472', normal, compile, [''])