Don't suggest enabling TypeApplications when it's already enabled
authorMaciej Bielecki <zyla@prati.pl>
Mon, 2 Jan 2017 22:03:00 +0000 (17:03 -0500)
committerBen Gamari <ben@smart-cactus.org>
Mon, 2 Jan 2017 22:44:50 +0000 (17:44 -0500)
Previously when encountering EAsPat in an expression context,
TypeApplications was suggested even when already enabled. This patch
replaces the suggestion with more appropriate message.

Test Plan: validate

Reviewers: austin, bgamari, mpickering, goldfire, simonpj

Reviewed By: mpickering, goldfire, simonpj

Subscribers: simonpj, goldfire, mpickering, thomie

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

GHC Trac Issues: #12879

compiler/rename/RnExpr.hs
testsuite/tests/rename/should_fail/T12879.hs [new file with mode: 0644]
testsuite/tests/rename/should_fail/T12879.stderr [new file with mode: 0644]
testsuite/tests/rename/should_fail/all.T

index 811ecba..17c9042 100644 (file)
@@ -336,8 +336,14 @@ We return a (bogus) EWildPat in each case.
 -}
 
 rnExpr EWildPat        = return (hsHoleExpr, emptyFVs)   -- "_" is just a hole
-rnExpr e@(EAsPat {})   =
-  patSynErr e (text "Did you mean to enable TypeApplications?")
+rnExpr e@(EAsPat {})
+  = do { opt_TypeApplications <- xoptM LangExt.TypeApplications
+       ; let msg | opt_TypeApplications
+                    = "Type application syntax requires a space before '@'"
+                 | otherwise
+                    = "Did you mean to enable TypeApplications?"
+       ; patSynErr e (text msg)
+       }
 rnExpr e@(EViewPat {}) = patSynErr e empty
 rnExpr e@(ELazyPat {}) = patSynErr e empty
 
diff --git a/testsuite/tests/rename/should_fail/T12879.hs b/testsuite/tests/rename/should_fail/T12879.hs
new file mode 100644 (file)
index 0000000..3f62207
--- /dev/null
@@ -0,0 +1,4 @@
+{-# LANGUAGE TypeApplications #-}
+module ShouldFail where
+
+f x = x@x
diff --git a/testsuite/tests/rename/should_fail/T12879.stderr b/testsuite/tests/rename/should_fail/T12879.stderr
new file mode 100644 (file)
index 0000000..1b3559c
--- /dev/null
@@ -0,0 +1,4 @@
+
+T12879.hs:4:7: error:
+    Pattern syntax in expression context: x@x
+    Type application syntax requires a space before '@'
index b8c1ac5..d42ca56 100644 (file)
@@ -142,3 +142,4 @@ test('T11663', normal, compile_fail, [''])
 test('T12229', normal, compile, [''])
 test('T12681', normal, multimod_compile_fail, ['T12681','-v0'])
 test('T12686', normal, compile_fail, [''])
+test('T12879', normal, compile_fail, [''])