summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2009-11-09 20:10:22 +0000
committerAdriaan Moors <adriaan.moors@epfl.ch>2009-11-09 20:10:22 +0000
commitcedd41ba4a14f7f1595057edfeca5437ef674bc3 (patch)
treea1e00f4a9a9c375d65688521f5d00396dc47b0f4 /src/compiler/scala/tools
parent7da30bf2d5195d1e7a156680b50167707f7a3d0a (diff)
downloadscala-cedd41ba4a14f7f1595057edfeca5437ef674bc3.tar.gz
scala-cedd41ba4a14f7f1595057edfeca5437ef674bc3.tar.bz2
scala-cedd41ba4a14f7f1595057edfeca5437ef674bc3.zip
fixed bug in implicit resolution that only mani...
fixed bug in implicit resolution that only manifested itself when multiple implicit arguments needed to be resolved and they were intended to instantiate type parameters two problems: - type parameters that could not be inferred where removed from undetparams erroneously - the successfully inferred parameters were not propagated to the the implicit arguments on the right (implicit resolution searches for implicit arguments from left to right, fixing type parameters in the process) this should give the green light for the addition of Zipped to TupleN
Diffstat (limited to 'src/compiler/scala/tools')
-rw-r--r--src/compiler/scala/tools/nsc/ast/Trees.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Implicits.scala12
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala11
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala14
4 files changed, 32 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala
index f8f6ee2c55..bff4bd51c3 100644
--- a/src/compiler/scala/tools/nsc/ast/Trees.scala
+++ b/src/compiler/scala/tools/nsc/ast/Trees.scala
@@ -1708,7 +1708,7 @@ trait Trees {
}
}
- class TreeTypeSubstituter(val from: List[Symbol], to: List[Type]) extends Traverser {
+ class TreeTypeSubstituter(val from: List[Symbol], val to: List[Type]) extends Traverser {
val typeSubst = new SubstTypeMap(from, to)
override def traverse(tree: Tree) {
if (tree.tpe ne null) tree.tpe = typeSubst(tree.tpe)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
index 75a6796be6..18831600b7 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
@@ -431,10 +431,16 @@ self: Analyzer =>
val targs = solvedTypes(tvars, undetParams, undetParams map varianceInType(pt),
false, lubDepth(List(itree2.tpe, pt)))
checkBounds(itree2.pos, NoPrefix, NoSymbol, undetParams, targs, "inferred ") // #2421
- val subst = new TreeTypeSubstituter(undetParams, targs)
+
+ // filter out failures from type inference, don't want to remove them from undetParams!
+ val uninstantiated = new ListBuffer[Symbol]
+ val detargs = adjustTypeArgs(undetParams, targs, pt, uninstantiated)
+ val (okParams, okArgs) = (undetParams zip detargs) filter {case (p, a) => !uninstantiated.contains(p)} unzip
+ // TODO: optimise above line(s?) once `zipped filter` works (oh, the irony! this line is needed to get Zipped to type check...)
+
+ val subst = new TreeTypeSubstituter(okParams, okArgs)
subst traverse itree2
- // todo: remove type params that have been instantiated to Nothing, similar
- // to methTypeArgs
+
val result = new SearchResult(itree2, subst)
if (traceImplicits) println("RESULT = "+result)
// println("RESULT = "+itree+"///"+itree1+"///"+itree2)//DEBUG
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
index 3e83ecf272..8b600bfd90 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -587,9 +587,15 @@ trait Infer {
* and treat them as uninstantiated parameters instead.
* Map T* entries to Seq[T].
*/
- def adjustTypeArgs(tparams: List[Symbol], targs: List[Type], restpe: Type, uninstantiated: ListBuffer[Symbol]): List[Type] =
+ def adjustTypeArgs(tparams: List[Symbol], targs: List[Type], restpe: Type, uninstantiated: ListBuffer[Symbol]): List[Type] = {
+ @inline def covariantOrNotContained(variance: Int) =
+ ((variance & COVARIANT) == 0) || // tparam occurred covariantly
+ (variance == VARIANCES) // tparam did not occur
+
List.map2(tparams, targs) {(tparam, targ) =>
- if (targ.typeSymbol == NothingClass && (restpe == WildcardType || (varianceInType(restpe)(tparam) & COVARIANT) == 0)) {
+ if (targ.typeSymbol == NothingClass &&
+ ( restpe == WildcardType
+ || covariantOrNotContained(varianceInType(restpe)(tparam)))) {
uninstantiated += tparam
tparam.tpeHK //@M tparam.tpe was wrong: we only want the type constructor,
// not the type constructor applied to dummy arguments
@@ -602,6 +608,7 @@ trait Infer {
targ.widen
}
}
+ }
/** Return inferred type arguments, given type parameters, formal parameters,
* argument types, result type and expected result type.
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 619f5324be..50627268c8 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -172,7 +172,19 @@ trait Typers { self: Analyzer =>
def applyImplicitArgs(fun: Tree): Tree = fun.tpe match {
case MethodType(params, _) =>
var positional = true
- val argResults = params map (p => inferImplicit(fun, p.tpe, true, false, context))
+ val argResultsBuff = new ListBuffer[SearchResult]()
+
+ // apply the substitutions (undet type param -> type) that were determined
+ // by implicit resolution of implicit arguments on the left of this argument
+ for(param <- params) {
+ var paramTp = param.tpe
+ for(ar <- argResultsBuff)
+ paramTp = paramTp.subst(ar.subst.from, ar.subst.to)
+
+ argResultsBuff += inferImplicit(fun, paramTp, true, false, context)
+ }
+
+ val argResults = argResultsBuff.toList
val args = argResults.zip(params) flatMap {
case (arg, param) =>
if (arg != SearchFailure) {