Skip to content

Commit fd7d511

Browse files
committed
Special case Array.scala compilation
Ported from scala/scala#5944
1 parent 029196b commit fd7d511

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala

+7-3
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,13 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
363363
}
364364
else {
365365
mnode.visitVarInsn(asm.Opcodes.ALOAD, 0)
366-
generatedType =
367-
if (tree.symbol == defn.ArrayClass) ObjectReference
368-
else classBTypeFromSymbol(claszSymbol)
366+
// When compiling Array.scala, the constructor invokes `Array.this.super.<init>`. The expectedType
367+
// is `[Object` (computed by typeToBType, the type of This(Array) is `Array[T]`). If we would set
368+
// the generatedType to `Array` below, the call to adapt at the end would fail. The situation is
369+
// similar for primitives (`I` vs `Int`).
370+
if (tree.symbol != defn.ArrayClass && !tree.symbol.isPrimitiveValueClass) {
371+
generatedType = classBTypeFromSymbol(claszSymbol)
372+
}
369373
}
370374

371375
case DesugaredSelect(Ident(nme.EMPTY_PACKAGE), module) =>

0 commit comments

Comments
 (0)