summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2018-10-18 15:41:44 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2018-10-24 16:38:55 +0100
commit6b1102e2cfcffb265fd33cf8a99ab5e6b3f14906 (patch)
tree564e90f34ac188a0fc22390f3975572007cf6b7b /compiler
parent7d9036448a394d7f2eeb158bb71d0fa694f88f56 (diff)
downloadhaskell-6b1102e2cfcffb265fd33cf8a99ab5e6b3f14906.tar.gz
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.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/typecheck/TcErrors.hs2
-rw-r--r--compiler/typecheck/TcRnTypes.hs24
2 files changed, 16 insertions, 10 deletions
diff --git a/compiler/typecheck/TcErrors.hs b/compiler/typecheck/TcErrors.hs
index 35f31d1b9e..951107bbcf 100644
--- a/compiler/typecheck/TcErrors.hs
+++ b/compiler/typecheck/TcErrors.hs
@@ -543,7 +543,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)
diff --git a/compiler/typecheck/TcRnTypes.hs b/compiler/typecheck/TcRnTypes.hs
index 695d2aea8a..bbd85aa1c6 100644
--- a/compiler/typecheck/TcRnTypes.hs
+++ b/compiler/typecheck/TcRnTypes.hs
@@ -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,
@@ -2387,7 +2387,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
@@ -2407,16 +2407,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]
- | isHoleCt ct = isOutOfScopeCt ct -- See Note [Insoluble holes]
- | insolubleEqCt ct = True
- | otherwise = False
+insolubleCt ct
+ | not (insolubleEqCt ct) = False
+ | isHoleCt ct = isOutOfScopeCt ct -- See Note [Insoluble holes]
+ | arisesFromGivens ct = False -- See Note [Given insolubles]
+ | otherwise = True
insolubleEqCt :: Ct -> Bool
-- Returns True of /equality/ constraints
@@ -2470,6 +2470,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.