Skip to content

Commit 030ca3c

Browse files
committed
Special case Array.scala compilation
Ported from scala/scala#5944
1 parent 8706f49 commit 030ca3c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

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

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

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

0 commit comments

Comments
 (0)