diff options
author | Martin Odersky <odersky@gmail.com> | 2014-11-28 22:10:37 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-11-28 22:12:51 +0100 |
commit | 91c61e4694097971b9a0c139048b7239d0f05588 (patch) | |
tree | 6836b169dce43f32e588f60bb16d14dba850b254 /src/dotty/tools/dotc/ast/tpd.scala | |
parent | b18ce863f5f2444a5a00ccc9d55c4ee12115c467 (diff) | |
download | dotty-91c61e4694097971b9a0c139048b7239d0f05588.tar.gz dotty-91c61e4694097971b9a0c139048b7239d0f05588.tar.bz2 dotty-91c61e4694097971b9a0c139048b7239d0f05588.zip |
Previous scheme was buggy; leaked Array types to backend.
Now: All new Array[T] methods are translated to calls of the form
dotty.Arrays.newXYZArray ...
Diffstat (limited to 'src/dotty/tools/dotc/ast/tpd.scala')
-rw-r--r-- | src/dotty/tools/dotc/ast/tpd.scala | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/ast/tpd.scala b/src/dotty/tools/dotc/ast/tpd.scala index 98609f9f1..98cc10a22 100644 --- a/src/dotty/tools/dotc/ast/tpd.scala +++ b/src/dotty/tools/dotc/ast/tpd.scala @@ -298,6 +298,24 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { case ConstantType(value) => Literal(value) } + /** A tree representing a `newXYZArray` operation of the right + * kind for the given element type in `typeArg`. No type arguments or + * `length` arguments are given. + */ + def newArray(typeArg: Tree, pos: Position)(implicit ctx: Context): Tree = { + val elemType = typeArg.tpe + val elemClass = elemType.classSymbol + def newArr(kind: String) = + ref(defn.DottyArraysModule).select(s"new${kind}Array".toTermName).withPos(pos) + if (TypeErasure.isUnboundedGeneric(elemType)) + newArr("Generic").appliedToTypeTrees(typeArg :: Nil) + else if (elemClass.isPrimitiveValueClass) + newArr(elemClass.name.toString) + else + newArr("Ref").appliedToTypeTrees( + TypeTree(defn.ArrayType(elemType)).withPos(typeArg.pos) :: Nil) + } + // ------ Creating typed equivalents of trees that exist only in untyped form ------- /** new C(args), calling the primary constructor of C */ @@ -678,7 +696,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { Throw(New(defn.ClassCastExceptionClass.typeRef, Nil)) withPos tree.pos } } - + def applyOverloaded(receiver: Tree, method: TermName, args: List[Tree], targs: List[Type], expectedType: Type, isAnnotConstructor: Boolean = false)(implicit ctx: Context): Tree = { val typer = ctx.typer val proto = new FunProtoTyped(args, expectedType, typer) |