summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala15
-rw-r--r--test/files/neg/t5845.check5
-rw-r--r--test/files/pos/t4881.scala31
3 files changed, 6 insertions, 45 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
index 0c3dcb9342..cb5fc8df5a 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -517,7 +517,7 @@ trait Infer extends Checkable {
val tvars = tparams map freshVar
if (isConservativelyCompatible(restpe.instantiateTypeParams(tparams, tvars), pt))
map2(tparams, tvars)((tparam, tvar) =>
- instantiateToBound(tvar, inferVariance(formals, restpe)(tparam)))
+ instantiateToBound(tvar, varianceInTypes(formals)(tparam)))
else
tvars map (tvar => WildcardType)
}
@@ -647,24 +647,13 @@ trait Infer extends Checkable {
"argument expression's type is not compatible with formal parameter type" + foundReqMsg(tp1, pt1))
}
}
-
val targs = solvedTypes(
- tvars, tparams, tparams map inferVariance(formals, restpe),
+ tvars, tparams, tparams map varianceInTypes(formals),
false, lubDepth(formals) max lubDepth(argtpes)
)
adjustTypeArgs(tparams, tvars, targs, restpe)
}
- /** Determine which variance to assume for the type paraneter. We first chose the variance
- * that minimizes any formal parameters. If that is still undetermined, because the type parameter
- * does not appear as a formal parameter type, then we pick the variance so that it minimizes the
- * method's result type instead.
- */
- private def inferVariance(formals: List[Type], restpe: Type)(tparam: Symbol): Int = {
- val v = varianceInTypes(formals)(tparam)
- if (v != VarianceFlags) v else varianceInType(restpe)(tparam)
- }
-
private[typechecker] def followApply(tp: Type): Type = tp match {
case NullaryMethodType(restp) =>
val restp1 = followApply(restp)
diff --git a/test/files/neg/t5845.check b/test/files/neg/t5845.check
index c0b402fccb..8c6100d6de 100644
--- a/test/files/neg/t5845.check
+++ b/test/files/neg/t5845.check
@@ -1,4 +1,7 @@
+t5845.scala:9: error: value +++ is not a member of Int
+ println(5 +++ 5)
+ ^
t5845.scala:15: error: value +++ is not a member of Int
println(5 +++ 5)
^
-one error found
+two errors found
diff --git a/test/files/pos/t4881.scala b/test/files/pos/t4881.scala
deleted file mode 100644
index 46cfad9793..0000000000
--- a/test/files/pos/t4881.scala
+++ /dev/null
@@ -1,31 +0,0 @@
-class Contra[-T]
-trait A
-trait B extends A
-trait C extends B
-
-// test improved variance inference: first try formals to see in which variance positions the type param appears;
-// only when that fails to determine variance, look at result type
-object Test {
- def contraLBUB[a >: C <: A](): Contra[a] = null
- def contraLB[a >: C](): Contra[a] = null
-
-{
- val x = contraLBUB() //inferred Contra[C] instead of Contra[A]
- val x1: Contra[A] = x
-}
-
-{
- val x = contraLB() //inferred Contra[C] instead of Contra[Any]
- val x1: Contra[Any] = x
-}
-
-{
- val x = contraLBUB // make sure it does the same thing as its ()-less counterpart
- val x1: Contra[A] = x
-}
-
-{
- val x = contraLB
- val x1: Contra[Any] = x
-}
-}