summaryrefslogtreecommitdiff
path: root/src/reflect/scala/reflect/internal/Variances.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/reflect/scala/reflect/internal/Variances.scala')
-rw-r--r--src/reflect/scala/reflect/internal/Variances.scala26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/reflect/scala/reflect/internal/Variances.scala b/src/reflect/scala/reflect/internal/Variances.scala
index ef22df3f2e..8d74065207 100644
--- a/src/reflect/scala/reflect/internal/Variances.scala
+++ b/src/reflect/scala/reflect/internal/Variances.scala
@@ -8,7 +8,7 @@ package reflect
package internal
import Variance._
-import scala.collection.{ mutable, immutable }
+import scala.collection.mutable
import scala.annotation.tailrec
/** See comments at scala.reflect.internal.Variance.
@@ -122,15 +122,21 @@ trait Variances {
* same is true of the parameters (ValDefs) unless we are inside a
* refinement, in which case they are checked from here.
*/
- def apply(tp: Type): Type = tp match {
- case _ if isUncheckedVariance(tp) => tp
- case _ if resultTypeOnly(tp) => this(tp.resultType)
- case TypeRef(_, sym, _) if sym.isAliasType => this(tp.normalize)
- case TypeRef(_, sym, _) if !sym.variance.isInvariant => checkVarianceOfSymbol(sym) ; mapOver(tp)
- case RefinedType(_, _) => withinRefinement(mapOver(tp))
- case ClassInfoType(parents, _, _) => parents foreach this ; tp
- case mt @ MethodType(_, result) => flipped(mt.paramTypes foreach this) ; this(result)
- case _ => mapOver(tp)
+ def apply(tp: Type): Type = {
+ tp match {
+ case _ if isUncheckedVariance(tp) =>
+ case _ if resultTypeOnly(tp) => this(tp.resultType)
+ case TypeRef(_, sym, _) if sym.isAliasType => this(tp.normalize)
+ case TypeRef(_, sym, _) if !sym.variance.isInvariant => checkVarianceOfSymbol(sym) ; mapOver(tp)
+ case RefinedType(_, _) => withinRefinement(mapOver(tp))
+ case ClassInfoType(parents, _, _) => parents foreach this
+ case mt @ MethodType(_, result) => flipped(mt.paramTypes foreach this) ; this(result)
+ case _ => mapOver(tp)
+ }
+ // We're using TypeMap here for type traversal only. To avoid wasteful symbol
+ // cloning during the recursion, it is important to return the input `tp`, rather
+ // than the result of the pattern match above, which normalizes types.
+ tp
}
def validateDefinition(base: Symbol) {
val saved = this.base