From 552d7aa113dfda5c33c909b4a7874799a7ff1a3e Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sun, 3 Jul 2011 20:00:25 +0000 Subject: Modified return type inference not to allow T* ... Modified return type inference not to allow T* to leak from varargs methods. Since I don't know what is supposed to be done about eta expansion of these methods, I left the behavior as it was (except the return type) and a boolean val in Types to change it. def id[T](xs: T*) = xs etaExpandKeepsStar = true // (id[Int] _) is Int* => Seq[Int] etaExpandKeepsStar = false // (id[Int] _) is Seq[Int] => Seq[Int] References #4176, leaving open pending resolution of eta expansion. Review by odersky. --- src/compiler/scala/reflect/internal/Types.scala | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/compiler/scala/reflect/internal/Types.scala') diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala index 75243c6e1c..840d66c558 100644 --- a/src/compiler/scala/reflect/internal/Types.scala +++ b/src/compiler/scala/reflect/internal/Types.scala @@ -2995,6 +2995,27 @@ A type's typeSymbol should never be inspected directly. } } + // Set to true for A* => Seq[A] + // (And it will only rewrite A* in method result types.) + // This is the pre-existing behavior. + // Or false for Seq[A] => Seq[A] + // (It will rewrite A* everywhere but method parameters.) + // This is the specified behavior. + private final val etaExpandKeepsStar = true + + object dropRepeatedParamType extends TypeMap { + def apply(tp: Type): Type = tp match { + case MethodType(params, restpe) => + MethodType(params, apply(restpe)) + case PolyType(tparams, restpe) => + PolyType(tparams, apply(restpe)) + case TypeRef(_, RepeatedParamClass, arg :: Nil) => + seqType(arg) + case _ => + if (etaExpandKeepsStar) tp else mapOver(tp) + } + } + // Hash consing -------------------------------------------------------------- private val initialUniquesCapacity = 4096 -- cgit v1.2.3