Skip to content

Commit 2828ef1

Browse files
committed
Decouple handling array constructors from typer.
It's done in a separate ArrayConstructors phase now.
1 parent e60a20d commit 2828ef1

File tree

4 files changed

+8
-14
lines changed

4 files changed

+8
-14
lines changed

src/dotty/tools/dotc/Compiler.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ class Compiler {
6363
new Getters,
6464
new ElimByName,
6565
new AugmentScala2Traits,
66-
new ResolveSuper),
66+
new ResolveSuper,
67+
new ArrayConstructors),
6768
List(new Erasure),
6869
List(new ElimErasedValueType,
6970
new VCElideAllocations,

src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
839839
case tpnme.Float => TYPE(defn.BoxedFloatModule)
840840
case tpnme.Double => TYPE(defn.BoxedDoubleModule)
841841
case tpnme.Unit => TYPE(defn.BoxedUnitModule)
842-
case _ => Literal(Constant(TypeErasure.erasure(tp)))
842+
case _ =>
843+
if(ctx.erasedTypes || !tp.derivesFrom(defn.ArrayClass))
844+
Literal(Constant(TypeErasure.erasure(tp)))
845+
else Literal(Constant(tp))
843846
}
844847
}
845848

src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ trait Applications extends Compatibility { self: Typer =>
556556
if (proto.argsAreTyped) new ApplyToTyped(tree, fun1, funRef, proto.typedArgs, pt)
557557
else new ApplyToUntyped(tree, fun1, funRef, proto, pt)(argCtx)
558558
val result = app.result
559-
convertNewArray(ConstFold(result))
559+
ConstFold(result)
560560
} { (failedVal, failedState) =>
561561
val fun2 = tryInsertImplicitOnQualifier(fun1, proto)
562562
if (fun1 eq fun2) {
@@ -632,15 +632,6 @@ trait Applications extends Compatibility { self: Typer =>
632632
def adaptTypeArg(tree: tpd.Tree, bound: Type)(implicit ctx: Context): tpd.Tree =
633633
tree.withType(tree.tpe.etaExpandIfHK(bound))
634634

635-
/** Rewrite `new Array[T](....)` trees to calls of newXYZArray methods. */
636-
def convertNewArray(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = tree match {
637-
case Apply(TypeApply(tycon, targ :: Nil), args) if tycon.symbol == defn.ArrayConstructor =>
638-
fullyDefinedType(tree.tpe, "array", tree.pos)
639-
tpd.cpy.Apply(tree)(newArray(targ, tree.pos), args)
640-
case _ =>
641-
tree
642-
}
643-
644635
def typedUnApply(tree: untpd.Apply, selType: Type)(implicit ctx: Context): Tree = track("typedUnApply") {
645636
val Apply(qual, args) = tree
646637

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,8 +1671,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
16711671
case _ => Nil
16721672
}
16731673
if (typeArgs.isEmpty) typeArgs = constrained(poly, tree)._2
1674-
convertNewArray(
1675-
adaptInterpolated(tree.appliedToTypes(typeArgs), pt, original))
1674+
adaptInterpolated(tree.appliedToTypes(typeArgs), pt, original)
16761675
}
16771676
case wtp =>
16781677
pt match {

0 commit comments

Comments
 (0)