Fix #11355.
authorRichard Eisenberg <eir@cis.upenn.edu>
Sat, 9 Jan 2016 16:18:53 +0000 (11:18 -0500)
committerRichard Eisenberg <eir@cis.upenn.edu>
Fri, 15 Jan 2016 20:43:43 +0000 (15:43 -0500)
Previously, the check for impredicative type applications was
in the wrong spot.

Test case: typecheck/should_fail/T11355

compiler/typecheck/TcValidity.hs
testsuite/tests/typecheck/should_fail/T11355.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T11355.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/all.T

index 79d3702..63118d0 100644 (file)
@@ -291,6 +291,7 @@ checkValidType :: UserTypeCtxt -> Type -> TcM ()
 checkValidType ctxt ty
   = do { traceTc "checkValidType" (ppr ty <+> text "::" <+> ppr (typeKind ty))
        ; rankn_flag  <- xoptM LangExt.RankNTypes
+       ; impred_flag <- xoptM LangExt.ImpredicativeTypes
        ; let gen_rank :: Rank -> Rank
              gen_rank r | rankn_flag = ArbitraryRank
                         | otherwise  = r
@@ -310,7 +311,12 @@ checkValidType ctxt ty
                  TySynCtxt _    -> rank0
 
                  ExprSigCtxt    -> rank1
-                 TypeAppCtxt    -> rank0
+                 TypeAppCtxt | impred_flag -> ArbitraryRank
+                             | otherwise   -> tyConArgMonoType
+                    -- Normally, ImpredicativeTypes is handled in check_arg_type,
+                    -- but visible type applications don't go through there.
+                    -- So we do this check here.
+
                  FunSigCtxt {}  -> rank1
                  InfSigCtxt _   -> ArbitraryRank        -- Inferred type
                  ConArgCtxt _   -> rank1 -- We are given the type of the entire
diff --git a/testsuite/tests/typecheck/should_fail/T11355.hs b/testsuite/tests/typecheck/should_fail/T11355.hs
new file mode 100644 (file)
index 0000000..4ec11d0
--- /dev/null
@@ -0,0 +1,5 @@
+{-# LANGUAGE TypeApplications, RankNTypes #-}
+
+module T11355 where
+
+foo = const @_ @((forall a. a) -> forall a. a) () (id @(forall a. a))
diff --git a/testsuite/tests/typecheck/should_fail/T11355.stderr b/testsuite/tests/typecheck/should_fail/T11355.stderr
new file mode 100644 (file)
index 0000000..cd3cc73
--- /dev/null
@@ -0,0 +1,9 @@
+
+T11355.hs:5:7: error:
+    • Illegal polymorphic or qualified type: forall (a1 :: TYPE t0). a1
+      GHC doesn't yet support impredicative polymorphism
+    • In the expression:
+        const @_ @((forall a. a) -> forall a. a) () (id @(forall a. a))
+      In an equation for ‘foo’:
+          foo
+            = const @_ @((forall a. a) -> forall a. a) () (id @(forall a. a))
index 9aef820..88ab499 100644 (file)
@@ -402,3 +402,4 @@ test('T11274', normal, compile_fail, [''])
 test('T10619', normal, compile_fail, [''])
 test('T11347', normal, compile_fail, [''])
 test('T11356', normal, compile_fail, [''])
+test('T11355', normal, compile_fail, [''])