summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2012-04-13 12:54:44 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2012-04-13 12:54:44 +0100
commit6bf815982df88468035593a07b0be593d1326af2 (patch)
tree85fa9a107b39e8cf275d94ccfb93aa027f5bf195
parent3377abeb6bd4623c5806936d0ee569d123c1aa59 (diff)
downloadhaskell-6bf815982df88468035593a07b0be593d1326af2.tar.gz
Allow overlaps when -XIncoherentInstances is in force
This change allows a top-level instance to be used even if there is a (potentially) overlapping local given. Which isn't fab, but it is what IncoherentInstances is *for*. This fixes the bug part of Trac #6002.
-rw-r--r--compiler/typecheck/TcInteract.lhs18
1 files changed, 10 insertions, 8 deletions
diff --git a/compiler/typecheck/TcInteract.lhs b/compiler/typecheck/TcInteract.lhs
index a2e0b993ed..88b4afb746 100644
--- a/compiler/typecheck/TcInteract.lhs
+++ b/compiler/typecheck/TcInteract.lhs
@@ -1883,7 +1883,9 @@ matchClassInst _ clas [ _, ty ] _
matchClassInst inerts clas tys loc
- = do { let pred = mkClassPred clas tys
+ = do { dflags <- getDynFlags
+ ; let pred = mkClassPred clas tys
+ incoherent_ok = xopt Opt_IncoherentInstances dflags
; mb_result <- matchClass clas tys
; untch <- getUntouchables
; traceTcS "matchClassInst" $ vcat [ text "pred =" <+> ppr pred
@@ -1894,11 +1896,12 @@ matchClassInst inerts clas tys loc
MatchInstMany -> return NoInstance -- defer any reactions of a multitude until
-- we learn more about the reagent
MatchInstSingle (_,_)
- | given_overlap untch ->
- do { traceTcS "Delaying instance application" $
+ | not incoherent_ok && given_overlap untch
+ -> -- see Note [Instance and Given overlap]
+ do { traceTcS "Delaying instance application" $
vcat [ text "Workitem=" <+> pprType (mkClassPred clas tys)
, text "Relevant given dictionaries=" <+> ppr givens_for_this_clas ]
- ; return NoInstance -- see Note [Instance and Given overlap]
+ ; return NoInstance
}
MatchInstSingle (dfun_id, mb_inst_tys) ->
@@ -1976,6 +1979,9 @@ This is arguably not easy to appear in practice due to our aggressive prioritiza
of equality solving over other constraints, but it is possible. I've added a test case
in typecheck/should-compile/GivenOverlapping.hs
+We ignore the overlap problem if -XIncoherentInstances is in force: see
+Trac #6002 for a worked-out example where this makes a difference.
+
Moreover notice that our goals here are different than the goals of the top-level
overlapping checks. There we are interested in validating the following principle:
@@ -1985,7 +1991,3 @@ overlapping checks. There we are interested in validating the following principl
But for the Given Overlap check our goal is just related to completeness of
constraint solving.
-
-
-
-