summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsheaf <sam.derbyshire@gmail.com>2021-12-06 10:13:06 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-12-07 06:29:38 -0500
commit7eb5606441bf11ba2ebd5f8904918dc82a2a3126 (patch)
tree752415cb996eec08cb4314e3f151839ce466a7bb
parent5dbdf8781cdf35799e73e270632af6aac8d92e51 (diff)
downloadhaskell-7eb5606441bf11ba2ebd5f8904918dc82a2a3126.tar.gz
More permissive parsing of higher-rank type IPs
The parser now accepts implicit parameters with higher-rank types, such as `foo :: (?ip :: forall a. a -> a) => ...` Before this patch, we instead insisted on parentheses like so: `foo :: (?ip :: (forall a. a -> a)) => ...` The rest of the logic surrounding implicit parameters is unchanged; in particular, even with ImpredicativeTypes, this idiom is not likely to be very useful. Fixes #20654
-rw-r--r--compiler/GHC/Parser.y2
-rw-r--r--docs/users_guide/9.4.1-notes.rst8
-rw-r--r--testsuite/tests/parser/should_fail/T20654a.hs7
-rw-r--r--testsuite/tests/parser/should_fail/T20654a.stderr13
-rw-r--r--testsuite/tests/parser/should_fail/T20654b.hs7
-rw-r--r--testsuite/tests/parser/should_fail/T20654b.stderr4
-rw-r--r--testsuite/tests/parser/should_fail/all.T2
7 files changed, 42 insertions, 1 deletions
diff --git a/compiler/GHC/Parser.y b/compiler/GHC/Parser.y
index d499341c36..d768ef2d04 100644
--- a/compiler/GHC/Parser.y
+++ b/compiler/GHC/Parser.y
@@ -2114,7 +2114,7 @@ ctype :: { LHsType GhcPs }
, hst_xqual = NoExtField
, hst_body = $3 })) }
- | ipvar '::' type {% acsA (\cs -> sLL $1 (reLoc $>) (HsIParamTy (EpAnn (glR $1) [mu AnnDcolon $2] cs) (reLocA $1) $3)) }
+ | ipvar '::' ctype {% acsA (\cs -> sLL $1 (reLoc $>) (HsIParamTy (EpAnn (glR $1) [mu AnnDcolon $2] cs) (reLocA $1) $3)) }
| type { $1 }
----------------------
diff --git a/docs/users_guide/9.4.1-notes.rst b/docs/users_guide/9.4.1-notes.rst
index 0e776672eb..5dac95565a 100644
--- a/docs/users_guide/9.4.1-notes.rst
+++ b/docs/users_guide/9.4.1-notes.rst
@@ -17,6 +17,14 @@ Compiler
all the checks are now done during typechecking. The error messages
now contain more detailed information about the specific check that was performed.
+- The parsing of implicit parameters is slightly more permissive, as GHC now allows ::
+
+ foo :: (?ip :: forall a. a -> a)
+
+ without requiring parentheses around ``forall a. a -> a``. Note that implicit
+ parameters with such kinds are unlikely to be very useful, due to
+ :ghc-ticket:`18759`.
+
``base`` library
~~~~~~~~~~~~~~~~
diff --git a/testsuite/tests/parser/should_fail/T20654a.hs b/testsuite/tests/parser/should_fail/T20654a.hs
new file mode 100644
index 0000000000..dccabe703f
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/T20654a.hs
@@ -0,0 +1,7 @@
+
+{-# LANGUAGE ImplicitParams, ImpredicativeTypes #-}
+
+module T20654a where
+
+foo :: (?poly :: forall a. a -> a) => Int -> Int
+foo x = ?poly x
diff --git a/testsuite/tests/parser/should_fail/T20654a.stderr b/testsuite/tests/parser/should_fail/T20654a.stderr
new file mode 100644
index 0000000000..eb9ed41cd3
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/T20654a.stderr
@@ -0,0 +1,13 @@
+
+T20654a.hs:7:9: error:
+ • Couldn't match type: forall a. a -> a
+ with: Int -> Int
+ arising from a functional dependency between constraints:
+ ‘?poly::Int -> Int’
+ arising from a use of implicit parameter ‘?poly’ at T20654a.hs:7:9-13
+ ‘?poly::forall a. a -> a’
+ arising from the type signature for:
+ foo :: (?poly::forall a. a -> a) => Int -> Int at T20654a.hs:6:1-48
+ • In the expression: ?poly
+ In the expression: ?poly x
+ In an equation for ‘foo’: foo x = ?poly x
diff --git a/testsuite/tests/parser/should_fail/T20654b.hs b/testsuite/tests/parser/should_fail/T20654b.hs
new file mode 100644
index 0000000000..54e400fc89
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/T20654b.hs
@@ -0,0 +1,7 @@
+
+{-# LANGUAGE ImplicitParams, ImpredicativeTypes #-}
+
+module T20654b where
+
+bar :: (?ip1 :: ?ip2 :: Int) => Int
+bar = ?ip2
diff --git a/testsuite/tests/parser/should_fail/T20654b.stderr b/testsuite/tests/parser/should_fail/T20654b.stderr
new file mode 100644
index 0000000000..ba7f6a356a
--- /dev/null
+++ b/testsuite/tests/parser/should_fail/T20654b.stderr
@@ -0,0 +1,4 @@
+
+T20654b.hs:6:17: error:
+ • Expected a type, but ‘?ip2 :: Int’ has kind ‘Constraint’
+ • In the type signature: bar :: (?ip1 :: ?ip2 :: Int) => Int
diff --git a/testsuite/tests/parser/should_fail/all.T b/testsuite/tests/parser/should_fail/all.T
index d75e82c032..b3a79e38c4 100644
--- a/testsuite/tests/parser/should_fail/all.T
+++ b/testsuite/tests/parser/should_fail/all.T
@@ -199,3 +199,5 @@ test('ViewPatternsFail', normal, compile_fail, [''])
test('ParserNoTH1', normal, compile_fail, [''])
test('ParserNoTH2', normal, compile_fail, [''])
test('T17865', normal, compile_fail, [''])
+test('T20654a', normal, compile_fail, [''])
+test('T20654b', normal, compile_fail, [''])