Fix #13909 by tweaking an error message.
authorRichard Eisenberg <rae@cs.brynmawr.edu>
Tue, 15 Aug 2017 23:07:59 +0000 (19:07 -0400)
committerBen Gamari <ben@smart-cactus.org>
Thu, 14 Sep 2017 17:12:40 +0000 (13:12 -0400)
GHC was complaining about numbers of arguments when the real
problem is impredicativity.

test case: typecheck/should_fail/T13909

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

index 7db611f..664031d 100644 (file)
@@ -2019,8 +2019,11 @@ mkExpectedActualMsg ty1 ty2 (TypeEqOrigin { uo_actual = act
                   | otherwise            = text "kind" <+> quotes (ppr exp)
 
     num_args_msg = case level of
-      TypeLevel -> Nothing
       KindLevel
+        | not (isMetaTyVarTy exp) && not (isMetaTyVarTy act)
+           -- if one is a meta-tyvar, then it's possible that the user
+           -- has asked for something impredicative, and we couldn't unify.
+           -- Don't bother with counting arguments.
         -> let n_act = count_args act
                n_exp = count_args exp in
            case n_act - n_exp of
@@ -2035,6 +2038,8 @@ mkExpectedActualMsg ty1 ty2 (TypeEqOrigin { uo_actual = act
                   | otherwise = text "more arguments to"  -- n > 1
              _ -> Nothing
 
+      _ -> Nothing
+
     maybe_num_args_msg = case num_args_msg of
       Nothing -> empty
       Just m  -> m
diff --git a/testsuite/tests/typecheck/should_fail/T13909.hs b/testsuite/tests/typecheck/should_fail/T13909.hs
new file mode 100644 (file)
index 0000000..4f0cbdc
--- /dev/null
@@ -0,0 +1,12 @@
+{-# LANGUAGE TypeInType #-}
+module T13909 where
+
+import Data.Kind
+
+data Hm (k :: Type) (a :: k) :: Type
+
+class HasName (a :: k) where
+  getName :: proxy a -> String
+
+instance HasName Hm where
+  getName _ = "Hm"
diff --git a/testsuite/tests/typecheck/should_fail/T13909.stderr b/testsuite/tests/typecheck/should_fail/T13909.stderr
new file mode 100644 (file)
index 0000000..599be5a
--- /dev/null
@@ -0,0 +1,5 @@
+
+T13909.hs:11:18: error:
+    • Expected kind ‘k0’, but ‘Hm’ has kind ‘forall k -> k -> *’
+    • In the first argument of ‘HasName’, namely ‘Hm’
+      In the instance declaration for ‘HasName Hm’
index 07a893b..230e5f4 100644 (file)
@@ -455,4 +455,5 @@ test('T13902', normal, compile_fail, [''])
 test('T11963', normal, compile_fail, [''])
 test('T14000', normal, compile_fail, [''])
 test('T14055', normal, compile_fail, [''])
+test('T13909', normal, compile_fail, [''])
 test('T14232', normal, compile_fail, [''])