Commit 47ae01bf authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari

RnExpr: Actually fail if patterns found in expression

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 bce99086)
parent f168a616
......@@ -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
......
......@@ -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, [''])
......
......@@ -4,6 +4,4 @@ module ShouldFail where
-- !!! Pattern syntax in expressions
f x = x @ x
g x = ~ x
h x = _
......@@ -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
{-# OPTIONS_GHC -fno-warn-typed-holes #-}
module ShouldFail where
-- !!! Pattern syntax in expressions
f x = ~ x
rnfail016a.hs:6:7: error: Pattern syntax in expression context: ~x
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment