summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsheaf <sam.derbyshire@gmail.com>2022-04-01 17:17:58 +0200
committerJakob Bruenker <jakob.bruenker@gmail.com>2022-04-01 20:36:01 +0200
commitaefb1e6d15749dd318e98a326d9df34b26c38cbd (patch)
tree8ccd34cc9c9fb1bff5697c3a945be44aecde3ee0
parent9a325b59aeba2b52af1ab9e4ca0b1a8aafc82a54 (diff)
downloadhaskell-aefb1e6d15749dd318e98a326d9df34b26c38cbd.tar.gz
Ensure implicit parameters are lifted
`tcExpr` typechecked implicit parameters by introducing a metavariable of kind `TYPE kappa`, without enforcing that `kappa ~ LiftedRep`. This patch instead creates a metavariable of kind `Type`. Fixes #21327
-rw-r--r--compiler/GHC/Tc/Gen/Expr.hs8
-rw-r--r--testsuite/tests/typecheck/should_fail/T21327.hs7
-rw-r--r--testsuite/tests/typecheck/should_fail/T21327.stderr8
-rw-r--r--testsuite/tests/typecheck/should_fail/all.T1
4 files changed, 19 insertions, 5 deletions
diff --git a/compiler/GHC/Tc/Gen/Expr.hs b/compiler/GHC/Tc/Gen/Expr.hs
index b5e9982f48..c9e4421a7d 100644
--- a/compiler/GHC/Tc/Gen/Expr.hs
+++ b/compiler/GHC/Tc/Gen/Expr.hs
@@ -240,11 +240,9 @@ tcExpr (NegApp x expr neg_expr) res_ty
; return (NegApp x expr' neg_expr') }
tcExpr e@(HsIPVar _ x) res_ty
- = do { {- Implicit parameters must have a *tau-type* not a
- type scheme. We enforce this by creating a fresh
- type variable as its type. (Because res_ty may not
- be a tau-type.) -}
- ip_ty <- newOpenFlexiTyVarTy
+ = do { ip_ty <- newFlexiTyVarTy liftedTypeKind
+ -- Create a unification type variable of kind 'Type'.
+ -- (The type of an implicit parameter must have kind 'Type'.)
; let ip_name = mkStrLitTy (hsIPNameFS x)
; ipClass <- tcLookupClass ipClassName
; ip_var <- emitWantedEvVar origin (mkClassPred ipClass [ip_name, ip_ty])
diff --git a/testsuite/tests/typecheck/should_fail/T21327.hs b/testsuite/tests/typecheck/should_fail/T21327.hs
new file mode 100644
index 0000000000..0f0fcc9e01
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T21327.hs
@@ -0,0 +1,7 @@
+{-# LANGUAGE ImplicitParams, MagicHash #-}
+
+module T21327 where
+
+import GHC.Exts
+
+foo () = (?p :: Int#)
diff --git a/testsuite/tests/typecheck/should_fail/T21327.stderr b/testsuite/tests/typecheck/should_fail/T21327.stderr
new file mode 100644
index 0000000000..3756d2e3ae
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T21327.stderr
@@ -0,0 +1,8 @@
+
+T21327.hs:7:11:
+ Couldn't match a lifted type with an unlifted type
+ When matching types
+ t0 :: *
+ Int# :: TYPE 'IntRep
+ In the expression: ?p :: Int#
+ In an equation for ‘foo’: foo () = (?p :: Int#)
diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T
index 939d9b156e..af529398f3 100644
--- a/testsuite/tests/typecheck/should_fail/all.T
+++ b/testsuite/tests/typecheck/should_fail/all.T
@@ -652,3 +652,4 @@ test('AmbigFDs', normal, compile_fail, [''])
test('T20064', normal, compile_fail, [''])
test('T21130', normal, compile_fail, [''])
test('T20768_fail', normal, compile_fail, [''])
+test('T21327', normal, compile_fail, [''])