diff options
-rw-r--r-- | compiler/typecheck/TcSimplify.lhs | 34 | ||||
-rw-r--r-- | testsuite/tests/indexed-types/should_fail/T5934.stderr | 8 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_compile/tc211.stderr | 107 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/T8603.stderr | 8 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/T9033.hs | 7 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/T9033.stderr | 5 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/all.T | 1 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/mc24.stderr | 16 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/tcfail004.stderr | 18 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/tcfail005.stderr | 17 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/tcfail140.stderr | 76 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/tcfail189.stderr | 16 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/tcfail206.stderr | 9 |
13 files changed, 153 insertions, 169 deletions
diff --git a/compiler/typecheck/TcSimplify.lhs b/compiler/typecheck/TcSimplify.lhs index 64ef3fed4b..8981a36a19 100644 --- a/compiler/typecheck/TcSimplify.lhs +++ b/compiler/typecheck/TcSimplify.lhs @@ -95,10 +95,9 @@ simpl_top wanteds try_class_defaulting :: WantedConstraints -> TcS WantedConstraints try_class_defaulting wc - | isEmptyWC wc || insolubleWC wc - = return wc -- Don't do type-class defaulting if there are insolubles - -- Doing so is not going to solve the insolubles - | otherwise + | isEmptyWC wc + = return wc + | otherwise -- See Note [When to do type-class defaulting] = do { something_happened <- applyDefaultingRules (approximateWC wc) -- See Note [Top-level Defaulting Plan] ; if something_happened @@ -107,6 +106,33 @@ simpl_top wanteds else return wc } \end{code} +Note [When to do type-class defaulting] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +In GHC 7.6 and 7.8.2, we did type-class defaulting only if insolubleWC +was false, on the grounds that defaulting can't help solve insoluble +constraints. But if we *don't* do defaulting we may report a whole +lot of errors that would be solved by defaulting; these errors are +quite spurious because fixing the single insoluble error means that +defaulting happens again, which makes all the other errors go away. +This is jolly confusing: Trac #9033. + +So it seems better to always do type-class defaulting. + +However, always doing defaulting does mean that we'll do it in +situations like this (Trac #5934): + run :: (forall s. GenST s) -> Int + run = fromInteger 0 +We don't unify the return type of fromInteger with the given function +type, because the latter involves foralls. So we're left with + (Num alpha, alpha ~ (forall s. GenST s) -> Int) +Now we do defaulting, get alpha := Integer, and report that we can't +match Integer with (forall s. GenST s) -> Int. That's not totally +stupid, but perhaps a little strange. + +Another potential alternative would be to suppress *all* non-insoluble +errors if there are *any* insoluble errors, anywhere, but that seems +too drastic. + Note [Must simplify after defaulting] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We may have a deeply buried constraint diff --git a/testsuite/tests/indexed-types/should_fail/T5934.stderr b/testsuite/tests/indexed-types/should_fail/T5934.stderr index 85ab1a1804..67a468057c 100644 --- a/testsuite/tests/indexed-types/should_fail/T5934.stderr +++ b/testsuite/tests/indexed-types/should_fail/T5934.stderr @@ -1,8 +1,8 @@ T5934.hs:12:7:
- Cannot instantiate unification variable ‘a0’
- with a type involving foralls:
- (forall s. Gen (PrimState (ST s))) -> Int
- Perhaps you want ImpredicativeTypes
+ Couldn't match type ‘Integer’
+ with ‘(forall s. Gen (PrimState (ST s))) -> Int’
+ Expected type: Integer -> (forall s. GenST s) -> Int
+ Actual type: Integer -> Integer
In the expression: 0
In an equation for ‘run’: run = 0
diff --git a/testsuite/tests/typecheck/should_compile/tc211.stderr b/testsuite/tests/typecheck/should_compile/tc211.stderr index bdc5bd1879..533155a657 100644 --- a/testsuite/tests/typecheck/should_compile/tc211.stderr +++ b/testsuite/tests/typecheck/should_compile/tc211.stderr @@ -1,82 +1,25 @@ - -tc211.hs:15:22: - Couldn't match type ‘forall a6. a6 -> a6’ with ‘a -> a’ - Expected type: [a -> a] - Actual type: [forall a. a -> a] - In the first argument of ‘head’, namely ‘foo’ - In the first argument of ‘(:) :: - (forall a. a -> a) - -> [forall a. a -> a] -> [forall a. a -> a]’, namely - ‘(head foo)’ - -tc211.hs:48:19: - Could not deduce (Num a2) arising from the literal ‘3’ - from the context (Num a) - bound by the inferred type of - h1 :: Num a => (forall a1. a1 -> a1) -> a - at tc211.hs:(47,1)-(49,9) - The type variable ‘a2’ is ambiguous - Relevant bindings include - y :: Pair a2 (Pair a3 b1) (bound at tc211.hs:48:10) - Note: there are several potential instances: - instance Num Double -- Defined in ‘GHC.Float’ - instance Num Float -- Defined in ‘GHC.Float’ - instance Integral a => Num (GHC.Real.Ratio a) - -- Defined in ‘GHC.Real’ - ...plus three others - In the first argument of ‘g’, namely ‘3’ - In the first argument of ‘P’, namely ‘(g 3)’ - In the expression: P (g 3) (g (P 3 4)) - -tc211.hs:48:28: - Could not deduce (Num a3) arising from the literal ‘3’ - from the context (Num a) - bound by the inferred type of - h1 :: Num a => (forall a1. a1 -> a1) -> a - at tc211.hs:(47,1)-(49,9) - The type variable ‘a3’ is ambiguous - Relevant bindings include - y :: Pair a2 (Pair a3 b1) (bound at tc211.hs:48:10) - Note: there are several potential instances: - instance Num Double -- Defined in ‘GHC.Float’ - instance Num Float -- Defined in ‘GHC.Float’ - instance Integral a => Num (GHC.Real.Ratio a) - -- Defined in ‘GHC.Real’ - ...plus three others - In the first argument of ‘P’, namely ‘3’ - In the first argument of ‘g’, namely ‘(P 3 4)’ - In the second argument of ‘P’, namely ‘(g (P 3 4))’ - -tc211.hs:48:30: - Could not deduce (Num b1) arising from the literal ‘4’ - from the context (Num a) - bound by the inferred type of - h1 :: Num a => (forall a1. a1 -> a1) -> a - at tc211.hs:(47,1)-(49,9) - The type variable ‘b1’ is ambiguous - Relevant bindings include - y :: Pair a2 (Pair a3 b1) (bound at tc211.hs:48:10) - Note: there are several potential instances: - instance Num Double -- Defined in ‘GHC.Float’ - instance Num Float -- Defined in ‘GHC.Float’ - instance Integral a => Num (GHC.Real.Ratio a) - -- Defined in ‘GHC.Real’ - ...plus three others - In the second argument of ‘P’, namely ‘4’ - In the first argument of ‘g’, namely ‘(P 3 4)’ - In the second argument of ‘P’, namely ‘(g (P 3 4))’ - -tc211.hs:70:9: - Couldn't match type ‘forall a7. a7 -> a7’ with ‘a6 -> a6’ - Expected type: List (forall a. a -> a) - -> (forall a. a -> a) -> a6 -> a6 - Actual type: List (forall a. a -> a) - -> (forall a. a -> a) -> forall a. a -> a - In the expression: - foo2 :: - List (forall a. a -> a) -> (forall a. a -> a) -> (forall a. a -> a) - In the expression: - (foo2 :: - List (forall a. a -> a) - -> (forall a. a -> a) -> (forall a. a -> a)) - xs1 (\ x -> x) +
+tc211.hs:15:22:
+ Couldn't match type ‘forall a1. a1 -> a1’ with ‘a -> a’
+ Expected type: [a -> a]
+ Actual type: [forall a. a -> a]
+ In the first argument of ‘head’, namely ‘foo’
+ In the first argument of ‘(:) ::
+ (forall a. a -> a)
+ -> [forall a. a -> a] -> [forall a. a -> a]’, namely
+ ‘(head foo)’
+
+tc211.hs:70:9:
+ Couldn't match type ‘forall a2. a2 -> a2’ with ‘a1 -> a1’
+ Expected type: List (forall a. a -> a)
+ -> (forall a. a -> a) -> a1 -> a1
+ Actual type: List (forall a. a -> a)
+ -> (forall a. a -> a) -> forall a. a -> a
+ In the expression:
+ foo2 ::
+ List (forall a. a -> a) -> (forall a. a -> a) -> (forall a. a -> a)
+ In the expression:
+ (foo2 ::
+ List (forall a. a -> a)
+ -> (forall a. a -> a) -> (forall a. a -> a))
+ xs1 (\ x -> x)
diff --git a/testsuite/tests/typecheck/should_fail/T8603.stderr b/testsuite/tests/typecheck/should_fail/T8603.stderr index cf12725281..8ee8cccb4a 100644 --- a/testsuite/tests/typecheck/should_fail/T8603.stderr +++ b/testsuite/tests/typecheck/should_fail/T8603.stderr @@ -1,11 +1,11 @@ T8603.hs:29:17:
- Couldn't match type ‘(->) [a0]’ with ‘[t1]’
- Expected type: [t1] -> StateT s RV t0
- Actual type: t2 ((->) [a0]) (StateT s RV t0)
+ Couldn't match type ‘(->) [a0]’ with ‘[Integer]’
+ Expected type: [Integer] -> StateT s RV t0
+ Actual type: t1 ((->) [a0]) (StateT s RV t0)
The function ‘lift’ is applied to two arguments,
but its type ‘([a0] -> StateT s RV t0)
- -> t2 ((->) [a0]) (StateT s RV t0)’
+ -> t1 ((->) [a0]) (StateT s RV t0)’
has only one
In a stmt of a 'do' block: prize <- lift uniform [1, 2, 3]
In the expression:
diff --git a/testsuite/tests/typecheck/should_fail/T9033.hs b/testsuite/tests/typecheck/should_fail/T9033.hs new file mode 100644 index 0000000000..cc9277fc17 --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/T9033.hs @@ -0,0 +1,7 @@ +module T9030 where + +bad :: Bool +bad = () + +square :: Integral i => i -> i +square x = x^2 diff --git a/testsuite/tests/typecheck/should_fail/T9033.stderr b/testsuite/tests/typecheck/should_fail/T9033.stderr new file mode 100644 index 0000000000..c2fd563124 --- /dev/null +++ b/testsuite/tests/typecheck/should_fail/T9033.stderr @@ -0,0 +1,5 @@ + +T9033.hs:4:7: + Couldn't match expected type ‘Bool’ with actual type ‘()’ + In the expression: () + In an equation for ‘bad’: bad = () diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T index 2407af51be..fe15e983e2 100644 --- a/testsuite/tests/typecheck/should_fail/all.T +++ b/testsuite/tests/typecheck/should_fail/all.T @@ -331,3 +331,4 @@ test('T8570', extra_clean(['T85570a.o', 'T8570a.hi','T85570b.o', 'T8570b.hi']), test('T8603', normal, compile_fail, ['']) test('T8806', normal, compile_fail, ['']) test('T8912', normal, compile_fail, ['']) +test('T9033', normal, compile_fail, ['']) diff --git a/testsuite/tests/typecheck/should_fail/mc24.stderr b/testsuite/tests/typecheck/should_fail/mc24.stderr index 0ddc66d97a..495693c9f8 100644 --- a/testsuite/tests/typecheck/should_fail/mc24.stderr +++ b/testsuite/tests/typecheck/should_fail/mc24.stderr @@ -1,8 +1,8 @@ - -mc24.hs:10:31: - Couldn't match type ‘[a0]’ with ‘a -> a1’ - Expected type: (a -> a1) -> [a] -> t [a] - Actual type: [a0] -> [a0] - Possible cause: ‘take’ is applied to too many arguments - In the expression: take 2 - In a stmt of a monad comprehension: then group by x using take 2 +
+mc24.hs:10:31:
+ Couldn't match type ‘[a0]’ with ‘a -> Integer’
+ Expected type: (a -> Integer) -> [a] -> t [a]
+ Actual type: [a0] -> [a0]
+ Possible cause: ‘take’ is applied to too many arguments
+ In the expression: take 2
+ In a stmt of a monad comprehension: then group by x using take 2
diff --git a/testsuite/tests/typecheck/should_fail/tcfail004.stderr b/testsuite/tests/typecheck/should_fail/tcfail004.stderr index df54f950c6..48840e7298 100644 --- a/testsuite/tests/typecheck/should_fail/tcfail004.stderr +++ b/testsuite/tests/typecheck/should_fail/tcfail004.stderr @@ -1,9 +1,9 @@ - -tcfail004.hs:3:9: - Couldn't match expected type ‘(t, t3)’ - with actual type ‘(t0, t1, t2)’ - Relevant bindings include - f :: t (bound at tcfail004.hs:3:2) - g :: t3 (bound at tcfail004.hs:3:4) - In the expression: (1, 2, 3) - In a pattern binding: (f, g) = (1, 2, 3) +
+tcfail004.hs:3:9:
+ Couldn't match expected type ‘(t, t1)’
+ with actual type ‘(Integer, Integer, Integer)’
+ Relevant bindings include
+ f :: t (bound at tcfail004.hs:3:2)
+ g :: t1 (bound at tcfail004.hs:3:4)
+ In the expression: (1, 2, 3)
+ In a pattern binding: (f, g) = (1, 2, 3)
diff --git a/testsuite/tests/typecheck/should_fail/tcfail005.stderr b/testsuite/tests/typecheck/should_fail/tcfail005.stderr index bae8697fe8..36f0e738e4 100644 --- a/testsuite/tests/typecheck/should_fail/tcfail005.stderr +++ b/testsuite/tests/typecheck/should_fail/tcfail005.stderr @@ -1,8 +1,9 @@ - -tcfail005.hs:3:9: - Couldn't match expected type ‘[t]’ with actual type ‘(t0, Char)’ - Relevant bindings include - h :: t (bound at tcfail005.hs:3:2) - i :: [t] (bound at tcfail005.hs:3:4) - In the expression: (1, 'a') - In a pattern binding: (h : i) = (1, 'a') +
+tcfail005.hs:3:9:
+ Couldn't match expected type ‘[t]’
+ with actual type ‘(Integer, Char)’
+ Relevant bindings include
+ h :: t (bound at tcfail005.hs:3:2)
+ i :: [t] (bound at tcfail005.hs:3:4)
+ In the expression: (1, 'a')
+ In a pattern binding: (h : i) = (1, 'a')
diff --git a/testsuite/tests/typecheck/should_fail/tcfail140.stderr b/testsuite/tests/typecheck/should_fail/tcfail140.stderr index bb45df3dee..7593497fe2 100644 --- a/testsuite/tests/typecheck/should_fail/tcfail140.stderr +++ b/testsuite/tests/typecheck/should_fail/tcfail140.stderr @@ -1,38 +1,38 @@ - -tcfail140.hs:10:7: - Couldn't match expected type ‘a0 -> t’ with actual type ‘Int’ - Relevant bindings include bar :: t (bound at tcfail140.hs:10:1) - The function ‘f’ is applied to two arguments, - but its type ‘Int -> Int’ has only one - In the expression: f 3 9 - In an equation for ‘bar’: bar = f 3 9 - -tcfail140.hs:12:10: - Couldn't match expected type ‘a1 -> t1’ with actual type ‘Int’ - Relevant bindings include - rot :: t -> t1 (bound at tcfail140.hs:12:1) - The operator ‘f’ takes two arguments, - but its type ‘Int -> Int’ has only one - In the expression: 3 `f` 4 - In an equation for ‘rot’: rot xs = 3 `f` 4 - -tcfail140.hs:14:15: - Couldn't match expected type ‘a -> b’ with actual type ‘Int’ - Relevant bindings include - xs :: [a] (bound at tcfail140.hs:14:5) - bot :: [a] -> [b] (bound at tcfail140.hs:14:1) - The operator ‘f’ takes two arguments, - but its type ‘Int -> Int’ has only one - In the first argument of ‘map’, namely ‘(3 `f`)’ - In the expression: map (3 `f`) xs - -tcfail140.hs:16:8: - Constructor ‘Just’ should have 1 argument, but has been given none - In the pattern: Just - In the expression: (\ Just x -> x) :: Maybe a -> a - In the expression: ((\ Just x -> x) :: Maybe a -> a) (Just 1) - -tcfail140.hs:19:1: - Couldn't match expected type ‘t0 -> Bool’ with actual type ‘Int’ - The equation(s) for ‘g’ have two arguments, - but its type ‘Int -> Int’ has only one +
+tcfail140.hs:10:7:
+ Couldn't match expected type ‘Integer -> t’ with actual type ‘Int’
+ Relevant bindings include bar :: t (bound at tcfail140.hs:10:1)
+ The function ‘f’ is applied to two arguments,
+ but its type ‘Int -> Int’ has only one
+ In the expression: f 3 9
+ In an equation for ‘bar’: bar = f 3 9
+
+tcfail140.hs:12:10:
+ Couldn't match expected type ‘Integer -> t1’ with actual type ‘Int’
+ Relevant bindings include
+ rot :: t -> t1 (bound at tcfail140.hs:12:1)
+ The operator ‘f’ takes two arguments,
+ but its type ‘Int -> Int’ has only one
+ In the expression: 3 `f` 4
+ In an equation for ‘rot’: rot xs = 3 `f` 4
+
+tcfail140.hs:14:15:
+ Couldn't match expected type ‘a -> b’ with actual type ‘Int’
+ Relevant bindings include
+ xs :: [a] (bound at tcfail140.hs:14:5)
+ bot :: [a] -> [b] (bound at tcfail140.hs:14:1)
+ The operator ‘f’ takes two arguments,
+ but its type ‘Int -> Int’ has only one
+ In the first argument of ‘map’, namely ‘(3 `f`)’
+ In the expression: map (3 `f`) xs
+
+tcfail140.hs:16:8:
+ Constructor ‘Just’ should have 1 argument, but has been given none
+ In the pattern: Just
+ In the expression: (\ Just x -> x) :: Maybe a -> a
+ In the expression: ((\ Just x -> x) :: Maybe a -> a) (Just 1)
+
+tcfail140.hs:19:1:
+ Couldn't match expected type ‘t0 -> Bool’ with actual type ‘Int’
+ The equation(s) for ‘g’ have two arguments,
+ but its type ‘Int -> Int’ has only one
diff --git a/testsuite/tests/typecheck/should_fail/tcfail189.stderr b/testsuite/tests/typecheck/should_fail/tcfail189.stderr index 69e8b3dbba..6bd08a266c 100644 --- a/testsuite/tests/typecheck/should_fail/tcfail189.stderr +++ b/testsuite/tests/typecheck/should_fail/tcfail189.stderr @@ -1,8 +1,8 @@ - -tcfail189.hs:10:31: - Couldn't match type ‘[a0]’ with ‘a -> a1’ - Expected type: (a -> a1) -> [a] -> [[a]] - Actual type: [a0] -> [a0] - Possible cause: ‘take’ is applied to too many arguments - In the expression: take 2 - In a stmt of a list comprehension: then group by x using take 2 +
+tcfail189.hs:10:31:
+ Couldn't match type ‘[a0]’ with ‘a -> Integer’
+ Expected type: (a -> Integer) -> [a] -> [[a]]
+ Actual type: [a0] -> [a0]
+ Possible cause: ‘take’ is applied to too many arguments
+ In the expression: take 2
+ In a stmt of a list comprehension: then group by x using take 2
diff --git a/testsuite/tests/typecheck/should_fail/tcfail206.stderr b/testsuite/tests/typecheck/should_fail/tcfail206.stderr index 4fe402982a..3eec7088cd 100644 --- a/testsuite/tests/typecheck/should_fail/tcfail206.stderr +++ b/testsuite/tests/typecheck/should_fail/tcfail206.stderr @@ -7,9 +7,9 @@ tcfail206.hs:5:5: In an equation for ‘a’: a = (, True)
tcfail206.hs:8:5:
- Couldn't match type ‘(t0, Int)’ with ‘Bool -> (Int, Bool)’
+ Couldn't match type ‘(Integer, Int)’ with ‘Bool -> (Int, Bool)’
Expected type: Int -> Bool -> (Int, Bool)
- Actual type: Int -> (t0, Int)
+ Actual type: Int -> (Integer, Int)
In the expression: (1,)
In an equation for ‘b’: b = (1,)
@@ -32,9 +32,10 @@ tcfail206.hs:14:5: In an equation for ‘d’: d = (# , True #)
tcfail206.hs:17:5:
- Couldn't match type ‘(# a0, Int #)’ with ‘Bool -> (# Int, Bool #)’
+ Couldn't match type ‘(# Integer, Int #)’
+ with ‘Bool -> (# Int, Bool #)’
Expected type: Int -> Bool -> (# Int, Bool #)
- Actual type: Int -> (# a0, Int #)
+ Actual type: Int -> (# Integer, Int #)
In the expression: (# 1, #)
In an equation for ‘e’: e = (# 1, #)
|