From a49228e3b6e3737da750bce59ec721b3b2f18eed Mon Sep 17 00:00:00 2001 From: Bartosz Nitka Date: Tue, 29 Mar 2016 12:42:16 +0200 Subject: Build correct substitution in instDFunType We will use `ty` in the range of the substitution, hence the substitution needs `ty`'s free vars in-scope. They don't seem easily available by other means, so we just compute them. Test Plan: ./validate Reviewers: austin, goldfire, bgamari, simonpj Reviewed By: simonpj Subscribers: thomie, simonmar Differential Revision: https://phabricator.haskell.org/D2043 GHC Trac Issues: #11371 --- compiler/typecheck/Inst.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/typecheck/Inst.hs b/compiler/typecheck/Inst.hs index ab9a4e28c7..49f57a59b1 100644 --- a/compiler/typecheck/Inst.hs +++ b/compiler/typecheck/Inst.hs @@ -306,14 +306,16 @@ instDFunType :: DFunId -> [DFunInstType] -- See Note [DFunInstType: instantiating types] in InstEnv instDFunType dfun_id dfun_inst_tys = do { (subst, inst_tys) <- go emptyTCvSubst dfun_tvs dfun_inst_tys - ; return (inst_tys, substThetaUnchecked subst dfun_theta) } + ; return (inst_tys, substTheta subst dfun_theta) } where (dfun_tvs, dfun_theta, _) = tcSplitSigmaTy (idType dfun_id) go :: TCvSubst -> [TyVar] -> [DFunInstType] -> TcM (TCvSubst, [TcType]) go subst [] [] = return (subst, []) go subst (tv:tvs) (Just ty : mb_tys) - = do { (subst', tys) <- go (extendTvSubst subst tv ty) tvs mb_tys + = do { (subst', tys) <- go (extendTvSubstAndInScope subst tv ty) + tvs + mb_tys ; return (subst', ty : tys) } go subst (tv:tvs) (Nothing : mb_tys) = do { (subst', tv') <- newMetaTyVarX subst tv -- cgit v1.2.1