[commit: ghc] master: Changed parser message for RankNTypes (#12811) (488a9da)

git at git.haskell.org git at git.haskell.org
Fri Mar 3 00:58:30 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/488a9daa8246e0dd364dc44b8b6b8650fa6f3822/ghc

>---------------------------------------------------------------

commit 488a9daa8246e0dd364dc44b8b6b8650fa6f3822
Author: Rupert Horlick <ruperthorlick at gmail.com>
Date:   Thu Mar 2 16:35:53 2017 -0500

    Changed parser message for RankNTypes (#12811)
    
    Added a check for whether RankNTypes is enabled
    and changed error message accordingly
    
    Reviewers: austin, bgamari
    
    Reviewed By: bgamari
    
    Subscribers: thomie, mpickering
    
    Differential Revision: https://phabricator.haskell.org/D3262


>---------------------------------------------------------------

488a9daa8246e0dd364dc44b8b6b8650fa6f3822
 compiler/parser/Parser.y                         | 22 +++++++++++++++++-----
 testsuite/tests/parser/should_fail/T12811.hs     |  5 +++++
 testsuite/tests/parser/should_fail/T12811.stderr |  7 +++++++
 testsuite/tests/parser/should_fail/all.T         |  1 +
 4 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/compiler/parser/Parser.y b/compiler/parser/Parser.y
index b590333..caa22dc 100644
--- a/compiler/parser/Parser.y
+++ b/compiler/parser/Parser.y
@@ -3181,11 +3181,7 @@ tyvarop :: { Located RdrName }
 tyvarop : '`' tyvarid '`'       {% ams (sLL $1 $> (unLoc $2))
                                        [mj AnnBackquote $1,mj AnnVal $2
                                        ,mj AnnBackquote $3] }
-        | '.'                   {% parseErrorSDoc (getLoc $1)
-                                      (vcat [text "Illegal symbol '.' in type",
-                                             text "Perhaps you intended to use RankNTypes or a similar language",
-                                             text "extension to enable explicit-forall syntax: forall <tvs>. <type>"])
-                                }
+        | '.'                   {% hintExplicitForall' (getLoc $1) }
 
 tyvarid :: { Located RdrName }
         : VARID            { sL1 $1 $! mkUnqual tvName (getVARID $1) }
@@ -3585,6 +3581,22 @@ hintExplicitForall span = do
       , text "extension to enable explicit-forall syntax: \x2200 <tvs>. <type>"
       ]
 
+-- Hint about explicit-forall, assuming UnicodeSyntax is off
+hintExplicitForall' :: SrcSpan -> P (GenLocated SrcSpan RdrName)
+hintExplicitForall' span = do
+    forall    <- extension explicitForallEnabled
+    let illegalDot = "Illegal symbol '.' in type"
+    if forall
+      then parseErrorSDoc span $ vcat
+        [ text illegalDot
+        , text "Perhaps you meant to write 'forall <tvs>. <type>'?"
+        ]
+      else parseErrorSDoc span $ vcat
+        [ text illegalDot
+        , text "Perhaps you intended to use RankNTypes or a similar language"
+        , text "extension to enable explicit-forall syntax: forall <tvs>. <type>"
+        ]
+
 {-
 %************************************************************************
 %*                                                                      *
diff --git a/testsuite/tests/parser/should_fail/T12811.hs b/testsuite/tests/parser/should_fail/T12811.hs
new file mode 100644
index 0000000..c82a830
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/T12811.hs
@@ -0,0 +1,5 @@
+{-# LANGUAGE RankNTypes #-}
+module Bug where
+
+foo :: foral a. a -> a
+foo x = x
diff --git a/testsuite/tests/parser/should_fail/T12811.stderr b/testsuite/tests/parser/should_fail/T12811.stderr
new file mode 100644
index 0000000..de22baf
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/T12811.stderr
@@ -0,0 +1,7 @@
+
+testsuite/tests/parser/should_fail/T12811.hs:4:15: error:
+    Illegal symbol '.' in type
+    Perhaps you meant to write 'forall <tvs>. <type>'?
+  |
+4 | foo :: foral a. a -> a
+  |               ^
diff --git a/testsuite/tests/parser/should_fail/all.T b/testsuite/tests/parser/should_fail/all.T
index e515e2f..b3efb5c 100644
--- a/testsuite/tests/parser/should_fail/all.T
+++ b/testsuite/tests/parser/should_fail/all.T
@@ -95,3 +95,4 @@ test('T10498a', normal, compile_fail, [''])
 test('T10498b', normal, compile_fail, [''])
 test('T12051', normal, compile_fail, [''])
 test('T12429', normal, compile_fail, [''])
+test('T12811', normal, compile_fail, [''])



More information about the ghc-commits mailing list