From 72da305329d3a8889e4e5f8d81a0ecad04b097ad Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 18 Jun 2008 15:39:36 +0000 Subject: gixed gilles' gadt problems. Added some tests --- src/compiler/scala/tools/nsc/symtab/Types.scala | 1 - src/compiler/scala/tools/nsc/typechecker/Infer.scala | 20 +++++++++++++++----- .../scala/tools/nsc/typechecker/Typers.scala | 5 +++-- 3 files changed, 18 insertions(+), 8 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index b1acd9f1d0..3221fa8601 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -3759,7 +3759,6 @@ A type's typeSymbol should never be inspected directly. * @param variances The variances of type parameters; need to reverse * solution direction for all contravariant variables. * @param upper When `true' search for max solution else min. - * @throws NoInstance */ def solve(tvars: List[TypeVar], tparams: List[Symbol], variances: List[Int], upper: Boolean): Boolean = { diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 1cec94d0d0..c6e069bf01 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -1055,9 +1055,16 @@ trait Infer { (lo, hi) } - def isInstantiatable(tvar: TypeVar) = { - val (lo, hi) = instBounds(tvar) - lo <:< hi + def isInstantiatable(tvars: List[TypeVar]) = { + def cloneTypeVar(tv: TypeVar) = { + val tv1 = TypeVar(tv.origin, new TypeConstraint(tv.constr.lobounds, tv.constr.hibounds)) + tv1.constr.inst = tv.constr.inst + tv1 + } + val tvars1 = tvars map cloneTypeVar + // Note: right now it's not clear that solving is complete, or how it can be made complete! + // So we should come back to this and investigate. + solve(tvars1, tvars1 map (_.origin.typeSymbol), tvars1 map (x => COVARIANT), false) } def instantiateTypeVar(tvar: TypeVar) { @@ -1160,14 +1167,17 @@ trait Infer { if (settings.debug.value) log("free type params (1) = " + tpparams) var tvars = tpparams map freshVar var tp = pattp.instantiateTypeParams(tpparams, tvars) - if (!((tp <:< pt) && (tvars forall isInstantiatable))) { + if (!((tp <:< pt) && isInstantiatable(tvars))) { tvars = tpparams map freshVar tp = pattp.instantiateTypeParams(tpparams, tvars) val ptparams = freeTypeParamsOfTerms.collect(pt) if (settings.debug.value) log("free type params (2) = " + ptparams) val ptvars = ptparams map freshVar val pt1 = pt.instantiateTypeParams(ptparams, ptvars) - if (!(isPopulated(tp, pt1) && (tvars forall isInstantiatable) && (ptvars forall isInstantiatable))) { + if (!(isPopulated(tp, pt1) && isInstantiatable(tvars ::: ptvars))) { + //println(tpparams) + //println(tvars map instBounds) + //println(ptvars map instBounds) error(pos, "pattern type is incompatible with expected type"+foundReqMsg(pattp, pt)) return pattp } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 40db3dd4a8..9f1d11f425 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2977,8 +2977,9 @@ trait Typers { self: Analyzer => case Bind(_, _) => if (arg.symbol.isAbstractType) arg.symbol setInfo // XXX, feedback. don't trackSymInfo here! - TypeBounds(lub(List(arg.symbol.info.bounds.lo, tparam.info.bounds.lo)), - glb(List(arg.symbol.info.bounds.hi, tparam.info.bounds.hi))) + TypeBounds( + lub(List(arg.symbol.info.bounds.lo, tparam.info.bounds.lo.subst(tparams, argtypes))), + glb(List(arg.symbol.info.bounds.hi, tparam.info.bounds.hi.subst(tparams, argtypes)))) case _ => }} TypeTree(owntype) setOriginal(tree) // setPos tree.pos -- cgit v1.2.3