RnExpr: Actually fail if patterns found in expression
authorBen Gamari <bgamari.foss@gmail.com>
Tue, 11 Oct 2016 13:26:46 +0000 (09:26 -0400)
committerBen Gamari <ben@smart-cactus.org>
Wed, 12 Oct 2016 15:55:28 +0000 (11:55 -0400)
This fixes #12584, where wildcard patterns were snuck into an
expression, which then crashed the typechecker in TcExpr since EWildPats
aren't supposed to appear in the AST after renaming.

The problem was that `rnTopSpliceDecl` failed to check for errors from
`rnSplice` (as done by other callers to `rnSplice`).

Thanks to Shayan for reporting this!

Reviewers: simonpj, austin

Reviewed By: simonpj

Subscribers: simonpj, thomie

Differential Revision: https://phabricator.haskell.org/D2539

GHC Trac Issues: #12584

(cherry picked from commit bce99086e9f54909f51ff5a74cb8c666083bb021)

compiler/rename/RnSplice.hs
testsuite/tests/rename/should_fail/all.T
testsuite/tests/rename/should_fail/rnfail016.hs
testsuite/tests/rename/should_fail/rnfail016.stderr
testsuite/tests/rename/should_fail/rnfail016a.hs [new file with mode: 0644]
testsuite/tests/rename/should_fail/rnfail016a.stderr [new file with mode: 0644]

index 0dc4487..c66886f 100644 (file)
@@ -593,8 +593,11 @@ rnSpliceDecl (SpliceDecl (L loc splice) flg)
 rnTopSpliceDecls :: HsSplice RdrName -> RnM ([LHsDecl RdrName], FreeVars)
 -- Declaration splice at the very top level of the module
 rnTopSpliceDecls splice
-   = do  { (rn_splice, fvs) <- setStage (Splice Untyped) $
+   = do  { (rn_splice, fvs) <- checkNoErrs $
+                               setStage (Splice Untyped) $
                                rnSplice splice
+           -- As always, be sure to checkNoErrs above lest we end up with
+           -- holes making it to typechecking, hence #12584.
          ; traceRn (text "rnTopSpliceDecls: untyped declaration splice")
          ; (decls, mod_finalizers) <-
               runRnSplice UntypedDeclSplice runMetaD ppr_decls rn_splice
index e9ea297..fc04e5c 100644 (file)
@@ -13,6 +13,7 @@ test('rnfail013', normal, compile_fail, [''])
 
 test('rnfail015', normal, compile_fail, [''])
 test('rnfail016', normal, compile_fail, [''])
+test('rnfail016a', normal, compile_fail, [''])
 test('rnfail017', normal, compile_fail, [''])
 test('rnfail018', normal, compile_fail, [''])
 test('rnfail019', normal, compile_fail, [''])
index 1bf15b0..7dccaa9 100644 (file)
@@ -4,6 +4,4 @@ module ShouldFail where
 -- !!! Pattern syntax in expressions
 
 f x = x @ x
-g x = ~ x
-h x = _
 
index 4013255..4743613 100644 (file)
@@ -2,5 +2,3 @@
 rnfail016.hs:6:7: error:
     Pattern syntax in expression context: x@x
     Did you mean to enable TypeApplications?
-
-rnfail016.hs:7:7: error: Pattern syntax in expression context: ~x
diff --git a/testsuite/tests/rename/should_fail/rnfail016a.hs b/testsuite/tests/rename/should_fail/rnfail016a.hs
new file mode 100644 (file)
index 0000000..e0d7d65
--- /dev/null
@@ -0,0 +1,6 @@
+{-# OPTIONS_GHC -fno-warn-typed-holes #-}
+module ShouldFail where
+
+-- !!! Pattern syntax in expressions
+
+f x = ~ x
diff --git a/testsuite/tests/rename/should_fail/rnfail016a.stderr b/testsuite/tests/rename/should_fail/rnfail016a.stderr
new file mode 100644 (file)
index 0000000..3a59ee7
--- /dev/null
@@ -0,0 +1,2 @@
+
+rnfail016a.hs:6:7: error: Pattern syntax in expression context: ~x