X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Ftypes%2FInstEnv.lhs;h=34bd5ebf469481ca8abb0bbda7635a12ecae9f88;hb=da43a382ccc7d3c57068976c312dc583fddc7498;hp=2d6a9eb215346b64574ccee53d5578e3ed046145;hpb=a3bab0506498db41853543558c52a4fda0d183af;p=ghc-hetmet.git diff --git a/compiler/types/InstEnv.lhs b/compiler/types/InstEnv.lhs index 2d6a9eb..34bd5eb 100644 --- a/compiler/types/InstEnv.lhs +++ b/compiler/types/InstEnv.lhs @@ -166,11 +166,14 @@ pprInstances :: [Instance] -> SDoc pprInstances ispecs = vcat (map pprInstance ispecs) instanceHead :: Instance -> ([TyVar], ThetaType, Class, [Type]) -instanceHead ispec - = (tvs, theta, cls, tys) +-- Returns the *source* theta, without the silent arguments +instanceHead ispec + = (tvs, drop n_silent theta, cls, tys) where - (tvs, theta, tau) = tcSplitSigmaTy (idType (is_dfun ispec)) - (cls, tys) = tcSplitDFunHead tau + (tvs, theta, tau) = tcSplitSigmaTy (idType dfun) + (cls, tys) = tcSplitDFunHead tau + dfun = is_dfun ispec + n_silent = dfunNSilent dfun mkLocalInstance :: DFunId -> OverlapFlag @@ -530,14 +533,18 @@ insert_overlapping new_item (item:items) old_beats_new = item `beats` new_item (instA, _) `beats` (instB, _) - = overlap_ok && - isJust (tcMatchTys (is_tvs instB) (is_tys instB) (is_tys instA)) - -- A beats B if A is more specific than B, and B admits overlap - -- I.e. if B can be instantiated to match A - where - overlap_ok = case is_flag instB of - NoOverlap -> False - _ -> True + = overlap_ok && + isJust (tcMatchTys (is_tvs instB) (is_tys instB) (is_tys instA)) + -- A beats B if A is more specific than B, + -- (ie. if B can be instantiated to match A) + -- and overlap is permitted + where + -- Overlap permitted if *either* instance permits overlap + -- This is a change (Trac #3877, Dec 10). It used to + -- require that instB (the less specific one) permitted overlap. + overlap_ok = case (is_flag instA, is_flag instB) of + (NoOverlap, NoOverlap) -> False + _ -> True \end{code}