Commit a49f95c2 authored by Simon Peyton Jones's avatar Simon Peyton Jones Committed by Ben Gamari

Report a Wanted error even if there are Given ones

We suppress some Given errors; see Note [Given errors]
in TcErrors.  But we must be careful not to suppress
Wanted errors because of the presence of these Given
errors -- else we might allow compilation to bogusly
proceed

The rubber hits the road in TcRnTypes.insolubleCt,
where we don't want to treat Givens as insoluble,
nor (and this is the new bit) Deriveds that arise
from Givens.  See Note [Given insolubles] in TcRnTypes.

This fixes #15767.

(cherry picked from commit 6b1102e2)

Ben notes:

  I have folded some test output changes in `TEST="T12529 T12921 mc13
  mc14"` into this patch that were not in the original.
parent b391cae1
......@@ -538,7 +538,7 @@ reportWanteds ctxt tc_lvl (WC { wc_simple = simples, wc_impl = implics })
-- report1: ones that should *not* be suppresed by
-- an insoluble somewhere else in the tree
-- It's crucial that anything that is considered insoluble
-- (see TcRnTypes.insolubleWantedCt) is caught here, otherwise
-- (see TcRnTypes.insolubleCt) is caught here, otherwise
-- we might suppress its error message, and proceed on past
-- type checking to get a Lint error later
report1 = [ ("Out of scope", is_out_of_scope, True, mkHoleReporter tidy_cts)
......
......@@ -89,7 +89,7 @@ module TcRnTypes(
isSolvedWC, andWC, unionsWC, mkSimpleWC, mkImplicWC,
addInsols, insolublesOnly, addSimples, addImplics,
tyCoVarsOfWC, dropDerivedWC, dropDerivedSimples,
tyCoVarsOfWCList, insolubleWantedCt, insolubleEqCt,
tyCoVarsOfWCList, insolubleCt, insolubleEqCt,
isDroppableCt, insolubleImplic,
arisesFromGivens,
......@@ -2382,7 +2382,7 @@ addInsols wc cts
insolublesOnly :: WantedConstraints -> WantedConstraints
-- Keep only the definitely-insoluble constraints
insolublesOnly (WC { wc_simple = simples, wc_impl = implics })
= WC { wc_simple = filterBag insolubleWantedCt simples
= WC { wc_simple = filterBag insolubleCt simples
, wc_impl = mapBag implic_insols_only implics }
where
implic_insols_only implic
......@@ -2402,16 +2402,16 @@ insolubleImplic ic = isInsolubleStatus (ic_status ic)
insolubleWC :: WantedConstraints -> Bool
insolubleWC (WC { wc_impl = implics, wc_simple = simples })
= anyBag insolubleWantedCt simples
= anyBag insolubleCt simples
|| anyBag insolubleImplic implics
insolubleWantedCt :: Ct -> Bool
insolubleCt :: Ct -> Bool
-- Definitely insoluble, in particular /excluding/ type-hole constraints
insolubleWantedCt ct
| isGivenCt ct = False -- See Note [Given insolubles]
insolubleCt ct
| not (insolubleEqCt ct) = False
| isHoleCt ct = isOutOfScopeCt ct -- See Note [Insoluble holes]
| insolubleEqCt ct = True
| otherwise = False
| arisesFromGivens ct = False -- See Note [Given insolubles]
| otherwise = True
insolubleEqCt :: Ct -> Bool
-- Returns True of /equality/ constraints
......@@ -2465,6 +2465,12 @@ because that'll suppress reports of [W] C b (f b). But we
may not report the insoluble [G] f b ~# b either (see Note [Given errors]
in TcErrors), so we may fail to report anything at all! Yikes.
The same applies to Derived constraints that /arise from/ Givens.
E.g. f :: (C Int [a]) => blah
where a fundep means we get
[D] Int ~ [a]
By the same reasoning we must not suppress other errors (Trac #15767)
Bottom line: insolubleWC (called in TcSimplify.setImplicationStatus)
should ignore givens even if they are insoluble.
......
mc13.hs:12:37: error: Variable not in scope: f :: [a] -> m a
mc13.hs:12:16: error:
• Ambiguous type variable ‘m0’ arising from a statement in a monad comprehension
prevents the constraint ‘(Monad m0)’ from being solved.
Relevant bindings include output :: m0 () (bound at mc13.hs:12:1)
Probable fix: use a type annotation to specify what ‘m0’ should be.
These potential instances exist:
instance Monad IO -- Defined in ‘GHC.Base’
instance Monad Maybe -- Defined in ‘GHC.Base’
instance Monoid a => Monad ((,) a) -- Defined in ‘GHC.Base’
...plus one other
...plus two instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In a stmt of a monad comprehension: then f
In the expression: [() | f <- functions, then f]
In an equation for ‘output’: output = [() | f <- functions, then f]
mc13.hs:12:37: error: Variable not in scope: f :: [a] -> m0 a
mc14.hs:14:49: error: Variable not in scope: f :: [a] -> m (t0 a)
mc14.hs:14:16: error:
• Ambiguous type variable ‘m0’ arising from a statement in a monad comprehension
prevents the constraint ‘(Monad m0)’ from being solved.
Relevant bindings include output :: m0 () (bound at mc14.hs:14:1)
Probable fix: use a type annotation to specify what ‘m0’ should be.
These potential instances exist:
instance Monad IO -- Defined in ‘GHC.Base’
instance Monad Maybe -- Defined in ‘GHC.Base’
instance Monoid a => Monad ((,) a) -- Defined in ‘GHC.Base’
...plus one other
...plus two instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In a stmt of a monad comprehension: then group using f
In the expression: [() | f <- functions, then group using f]
In an equation for ‘output’:
output = [() | f <- functions, then group using f]
mc14.hs:14:16: error:
• Ambiguous type variable ‘t0’ arising from a use of ‘fmap’
prevents the constraint ‘(Functor t0)’ from being solved.
Probable fix: use a type annotation to specify what ‘t0’ should be.
These potential instances exist:
instance Functor IO -- Defined in ‘GHC.Base’
instance Functor Maybe -- Defined in ‘GHC.Base’
instance Functor ((,) a) -- Defined in ‘GHC.Base’
...plus one other
...plus two instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the expression: fmap
In a stmt of a monad comprehension: then group using f
In the expression: [() | f <- functions, then group using f]
mc14.hs:14:49: error: Variable not in scope: f :: [a] -> m0 (t0 a)
T12529.hs:5:5: error: Variable not in scope: p
T12529.hs:5:5: error:
• Cannot apply expression of type ‘t1’
to a visible type argument ‘Int’
......
......@@ -27,6 +27,3 @@ T12921.hs:4:16: error:
(use -fprint-potential-instances to see them all)
• In the annotation:
{-# ANN module "HLint: ignore Reduce duplication" #-}
T12921.hs:7:8: error:
Variable not in scope: choice :: [a0] -> Int -> Int
{-# LANGUAGE FunctionalDependencies, FlexibleContexts #-}
module T15767 where
class C a b | b -> a where f :: a -> b
y = x where
x :: (C () b, C Bool b) => b
x = f ()
T15767.hs:7:5: error:
• No instance for (C () b) arising from a use of ‘x’
• In the expression: x
In an equation for ‘y’:
y = x
where
x :: (C () b, C Bool b) => b
x = f ()
......@@ -476,3 +476,4 @@ test('T14904b', normal, compile_fail, [''])
test('T15067', normal, compile_fail, [''])
test('T15361', normal, compile_fail, [''])
test('T15527', normal, compile_fail, [''])
test('T15767', normal, compile_fail, [''])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment