Fix panic on [t| _ |] (Trac #9879)
authorThomas Winant <thomas.winant@cs.kuleuven.be>
Mon, 15 Dec 2014 15:47:07 +0000 (09:47 -0600)
committerAustin Seipp <austin@well-typed.com>
Mon, 15 Dec 2014 15:47:07 +0000 (09:47 -0600)
Summary:
Type brackets containing a wildcard, e.g. `[t| _ |]`, caused a panic.
Fix it by disallowing wildcards in type brackets.

Together with D572, this fixes #9879.

Test Plan: new test WildcardInTypeBrackets should pass

Reviewers: austin

Reviewed By: austin

Subscribers: carter, thomie, monoidal

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

GHC Trac Issues: #9879

compiler/parser/Parser.y
testsuite/tests/partial-sigs/should_fail/WildcardInTypeBrackets.hs [new file with mode: 0644]
testsuite/tests/partial-sigs/should_fail/WildcardInTypeBrackets.stderr [new file with mode: 0644]
testsuite/tests/partial-sigs/should_fail/all.T

index 1849fb4..bffe6e1 100644 (file)
@@ -2081,7 +2081,10 @@ aexp2   :: { LHsExpr RdrName }
         | TH_TY_QUOTE gtycon    { sLL $1 $> $ HsBracket (VarBr False (unLoc $2)) }
         | '[|' exp '|]'       {% ams (sLL $1 $> $ HsBracket (ExpBr $2)) [mo $1,mc $3] }
         | '[||' exp '||]'     {% ams (sLL $1 $> $ HsBracket (TExpBr $2)) [mo $1,mc $3]}
-        | '[t|' ctype '|]'    {% ams (sLL $1 $> $ HsBracket (TypBr $2)) [mo $1,mc $3] }
+        | '[t|' ctype '|]'    {% checkNoPartialType
+                                   (text "in type brackets" <> colon
+                                    <+> quotes (text "[t|" <+> ppr $2 <+> text "|]")) $2 >>
+                                 ams (sLL $1 $> $ HsBracket (TypBr $2)) [mo $1,mc $3] }
         | '[p|' infixexp '|]' {% checkPattern empty $2 >>= \p ->
                                       ams (sLL $1 $> $ HsBracket (PatBr p))
                                           [mo $1,mc $3] }
diff --git a/testsuite/tests/partial-sigs/should_fail/WildcardInTypeBrackets.hs b/testsuite/tests/partial-sigs/should_fail/WildcardInTypeBrackets.hs
new file mode 100644 (file)
index 0000000..f11ac5a
--- /dev/null
@@ -0,0 +1,4 @@
+{-# LANGUAGE TemplateHaskell #-}
+module WildcardInTypeBrackets where
+
+foo = [t| _ |]
diff --git a/testsuite/tests/partial-sigs/should_fail/WildcardInTypeBrackets.stderr b/testsuite/tests/partial-sigs/should_fail/WildcardInTypeBrackets.stderr
new file mode 100644 (file)
index 0000000..dd6feb9
--- /dev/null
@@ -0,0 +1,4 @@
+
+WildcardInTypeBrackets.hs:4:11:
+    Wildcard not allowed
+    in type brackets: ‘[t| _ |]’
index ef08d37..c275e93 100644 (file)
@@ -36,6 +36,7 @@ test('WildcardsInPatternAndExprSig', normal, compile_fail, [''])
 test('WildcardInPatSynSig', normal, compile_fail, [''])
 test('WildcardInNewtype', normal, compile_fail, [''])
 test('WildcardInstantiations', normal, compile_fail, [''])
+test('WildcardInTypeBrackets', [req_interp, only_compiler_types(['ghc'])], compile_fail, [''])
 test('WildcardInTypeFamilyInstanceLHS', normal, compile_fail, [''])
 test('WildcardInTypeFamilyInstanceRHS', normal, compile_fail, [''])
 test('WildcardInTypeSynonymLHS', normal, compile_fail, [''])