Disallow unboxed string literals in patterns (#13260)
authorRupert Horlick <ruperthorlick@gmail.com>
Mon, 6 Mar 2017 18:44:40 +0000 (13:44 -0500)
committerBen Gamari <ben@smart-cactus.org>
Mon, 6 Mar 2017 22:23:02 +0000 (17:23 -0500)
Signed-off-by: Rupert Horlick <ruperthorlick@gmail.com>
Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie

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

compiler/parser/RdrHsSyn.hs
testsuite/tests/parser/should_fail/T13260.hs [new file with mode: 0644]
testsuite/tests/parser/should_fail/T13260.stderr [new file with mode: 0644]
testsuite/tests/parser/should_fail/all.T

index 2c63c42..e06c7e3 100644 (file)
@@ -829,6 +829,9 @@ checkAPat msg loc e0 = do
  case e0 of
    EWildPat -> return (WildPat placeHolderType)
    HsVar x  -> return (VarPat x)
+   HsLit (HsStringPrim _ _) -- (#13260)
+       -> parseErrorSDoc loc (text "Illegal unboxed string literal in pattern:" $$ ppr e0)
+
    HsLit l  -> return (LitPat l)
 
    -- Overloaded numeric patterns (e.g. f 0 x = x)
diff --git a/testsuite/tests/parser/should_fail/T13260.hs b/testsuite/tests/parser/should_fail/T13260.hs
new file mode 100644 (file)
index 0000000..b0e1f97
--- /dev/null
@@ -0,0 +1,7 @@
+{-# LANGUAGE MagicHash #-}
+
+module T13260 where
+
+  g y = case y of
+    "a"# -> True
+    _    -> False
diff --git a/testsuite/tests/parser/should_fail/T13260.stderr b/testsuite/tests/parser/should_fail/T13260.stderr
new file mode 100644 (file)
index 0000000..05e99d6
--- /dev/null
@@ -0,0 +1,4 @@
+
+T13260.hs:6:5: error:
+    Illegal unboxed string literal in pattern:
+    "a"#
index b3efb5c..1496fec 100644 (file)
@@ -96,3 +96,4 @@ test('T10498b', normal, compile_fail, [''])
 test('T12051', normal, compile_fail, [''])
 test('T12429', normal, compile_fail, [''])
 test('T12811', normal, compile_fail, [''])
+test('T13260', normal, compile_fail, [''])