diff options
author | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-11-25 09:38:21 +0000 |
---|---|---|
committer | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-11-25 09:38:21 +0000 |
commit | e83bcb3fc5cff4dab80120728bdfb23ca1ff70fd (patch) | |
tree | b4651d8d35e9b6f6bb3c866a58eebb9d169c62ef /src | |
parent | b766d4bc9a87ec988d1e9b6af7373b7501e44daa (diff) | |
download | scala-e83bcb3fc5cff4dab80120728bdfb23ca1ff70fd.tar.gz scala-e83bcb3fc5cff4dab80120728bdfb23ca1ff70fd.tar.bz2 scala-e83bcb3fc5cff4dab80120728bdfb23ca1ff70fd.zip |
Further fixes some issues for #3621.
Review by Rytz.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/UnCurry.scala | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala index d1a4672805..7538043d8f 100644 --- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala +++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala @@ -734,11 +734,20 @@ abstract class UnCurry extends InfoTransform with TypingTransformers with ast.Tr */ private def addJavaVarargsForwarders(dd: DefDef, flatdd: DefDef, tree: Tree) = if (repeatedParams.contains(dd.symbol)) { def toArrayType(tp: Type): Type = tp match { - case TypeRef(_, SeqClass, List(tparg)) => arrayType(tparg) + case TypeRef(_, SeqClass, List(tparg)) => + // to prevent generation of an `Object` parameter from `Array[T]` parameter later + // as this would crash the Java compiler which expects an `Object[]` array for varargs + // e.g. def foo[T](a: Int, b: T*) + // becomes def foo[T](a: Int, b: Array[Object]) + // instead of def foo[T](a: Int, b: Array[T]) ===> def foo[T](a: Int, b: Object) + if (tparg.typeSymbol.isTypeSkolem) arrayType(ObjectClass.tpe) else arrayType(tparg) } def toSeqType(tp: Type): Type = tp match { case TypeRef(_, ArrayClass, List(tparg)) => seqType(tparg) } + def seqElemType(tp: Type): Type = tp match { + case TypeRef(_, SeqClass, List(tparg)) => tparg + } def arrayElemType(tp: Type): Type = tp match { case TypeRef(_, ArrayClass, List(tparg)) => tparg } @@ -772,7 +781,10 @@ abstract class UnCurry extends InfoTransform with TypingTransformers with ast.Tr val locals: List[ValDef] = for ((argsym, fp) <- (forwsym ARGS) zip flatparams) yield if (rpsymbols contains fp.symbol) VAL(forwsym.newValue(unit.fresh.newName("param$")).setInfo(fp.symbol.tpe)) === { - gen.mkWrapArray(Ident(argsym), arrayElemType(argsym.tpe)) + gen.mkCast( + gen.mkWrapArray(Ident(argsym), arrayElemType(argsym.tpe)), + seqType(seqElemType(fp.symbol.tpe)) + ) } else null val emitted = for (l <- locals if l != null) yield l @@ -791,7 +803,7 @@ abstract class UnCurry extends InfoTransform with TypingTransformers with ast.Tr } // check if the method with that name and those arguments already exists in the template - currentClass.info.decls.lookupAll(forwsym.name).find(s => s != forwsym && s.tpe.matches(forwsym.tpe)) match { + currentClass.info.member(forwsym.name).alternatives.find(s => s != forwsym && s.tpe.matches(forwsym.tpe)) match { case Some(s) => unit.error(dd.symbol.pos, "A method with a varargs annotation produces a forwarder method with the same signature " + s.tpe + " as an existing method.") |