From c46145f0408b30bbd126d293ccf67792f307479a Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Tue, 24 Nov 2009 09:09:49 +0000 Subject: close #2665 and close #2667: use weak conforman... close #2665 and close #2667: use weak conformance in polymorphic case of isApplicable reviewed by: odersky exprTypeArgs now takes a comparison function: isWeaklyCompatible is ) passed in isApplicable's typesCompatible (to mimic what happens in the ) monomorphic case Martin: please review as this is different from my ) original proposal (that one broke type inference, this one passes all ) tests and does not slow down quick.comp ) --- src/compiler/scala/tools/nsc/typechecker/Infer.scala | 7 ++++--- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 712d469662..d11f263677 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -496,9 +496,9 @@ trait Infer { * @param pt ... * @return ... */ - private def exprTypeArgs(tparams: List[Symbol], restpe: Type, pt: Type): List[Type] = { + private def exprTypeArgs(tparams: List[Symbol], restpe: Type, pt: Type, checkCompat: (Type, Type) => Boolean = isCompatible): List[Type] = { val tvars = tparams map freshVar - if (isCompatible(restpe.instantiateTypeParams(tparams, tvars), pt)) { + if (checkCompat(restpe.instantiateTypeParams(tparams, tvars), pt)) { try { // If the restpe is an implicit method, and the expected type is fully defined // optimze type varianbles wrt to the implicit formals only; ignore the result type. @@ -788,7 +788,8 @@ trait Infer { try { val uninstantiated = new ListBuffer[Symbol] val targs = methTypeArgs(undetparams, formals, restpe, argtpes, pt, uninstantiated) - (exprTypeArgs(uninstantiated.toList, restpe.instantiateTypeParams(undetparams, targs), pt) ne null) && + // #2665: must use weak conformance, not regular one (follow the monorphic case above) + (exprTypeArgs(uninstantiated.toList, restpe.instantiateTypeParams(undetparams, targs), pt, isWeaklyCompatible) ne null) && isWithinBounds(NoPrefix, NoSymbol, undetparams, targs) } catch { case ex: NoInstance => false diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 1a8db1f27d..c3ca5d7e30 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2148,6 +2148,10 @@ trait Typers { self: Analyzer => val pre = fun.symbol.tpe.prefix var sym = fun.symbol filter { alt => + // must use pt as expected type, not WildcardType (a tempting quick fix to #2665) + // now fixed by using isWeaklyCompatible in exprTypeArgs + // TODO: understand why exactly -- some types were not inferred anymore (`ant clean quick.bin` failed) + // (I had expected inferMethodAlternative to pick up the slack introduced by using WildcardType here) isApplicableSafe(context.undetparams, followApply(pre.memberType(alt)), argtypes, pt) } if (sym hasFlag OVERLOADED) { -- cgit v1.2.3