diff --git a/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java b/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java index 7d2b11097..d54fd64c6 100644 --- a/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java +++ b/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java @@ -198,11 +198,7 @@ public class ClassGenerator { @Override public void visit(ConstructMultiArrayInstruction insn) { - ValueType type = insn.getItemType(); - for (int i = 0; i < insn.getDimensions().size(); ++i) { - type = ValueType.arrayOf(type); - } - addType(type); + addType(insn.getItemType()); } }; diff --git a/core/src/main/java/org/teavm/backend/wasm/generate/WasmGenerationVisitor.java b/core/src/main/java/org/teavm/backend/wasm/generate/WasmGenerationVisitor.java index 50231d419..270d27af1 100644 --- a/core/src/main/java/org/teavm/backend/wasm/generate/WasmGenerationVisitor.java +++ b/core/src/main/java/org/teavm/backend/wasm/generate/WasmGenerationVisitor.java @@ -1326,7 +1326,7 @@ class WasmGenerationVisitor implements StatementVisitor, ExprVisitor { WasmInt32Subtype.INT32)); } - int classPointer = classGenerator.getClassPointer(ValueType.arrayOf(type)); + int classPointer = classGenerator.getClassPointer(type); String allocName = context.names.forMethod(new MethodReference(Allocator.class, "allocateMultiArray", RuntimeClass.class, Address.class, int.class, RuntimeArray.class)); WasmCall call = new WasmCall(allocName); diff --git a/core/src/main/java/org/teavm/model/analysis/ClassInference.java b/core/src/main/java/org/teavm/model/analysis/ClassInference.java index dd7bfc250..bd3856215 100644 --- a/core/src/main/java/org/teavm/model/analysis/ClassInference.java +++ b/core/src/main/java/org/teavm/model/analysis/ClassInference.java @@ -828,11 +828,7 @@ public class ClassInference { @Override public void visit(ConstructMultiArrayInstruction insn) { - ValueType type = insn.getItemType(); - for (int i = 0; i < insn.getDimensions().size(); ++i) { - type = ValueType.arrayOf(type); - } - addType(insn.getReceiver().getIndex(), 0, type.toString()); + addType(insn.getReceiver().getIndex(), 0, insn.getItemType().toString()); } @Override diff --git a/core/src/main/java/org/teavm/model/util/TypeInferer.java b/core/src/main/java/org/teavm/model/util/TypeInferer.java index 747fb4d86..a9c59d8b7 100644 --- a/core/src/main/java/org/teavm/model/util/TypeInferer.java +++ b/core/src/main/java/org/teavm/model/util/TypeInferer.java @@ -260,7 +260,7 @@ public class TypeInferer { @Override public void createArray(VariableReader receiver, ValueType itemType, List dimensions) { - types[receiver.getIndex()] = convert(ValueType.arrayOf(itemType)); + types[receiver.getIndex()] = convert(itemType); } @Override diff --git a/tests/src/test/java/org/teavm/vm/VMTest.java b/tests/src/test/java/org/teavm/vm/VMTest.java index 455ac39c7..0d531163c 100644 --- a/tests/src/test/java/org/teavm/vm/VMTest.java +++ b/tests/src/test/java/org/teavm/vm/VMTest.java @@ -42,6 +42,32 @@ public class VMTest { assertEquals(int[].class, array[0].getClass()); } + @Test + public void longMultiArrayCreated() { + long[][] array = new long[3][2]; + assertEquals(3, array.length); + assertEquals(2, array[1].length); + assertEquals(2, array[2].length); + + for (int i = 0; i < array.length; ++i) { + assertEquals(2, array[i].length); + for (int j = 0; j < array[i].length; ++j) { + assertEquals(0, array[i][j]); + } + } + + for (int i = 0; i < array.length; ++i) { + Arrays.fill(array[i], 0x0123456789ABCDEFL); + } + + for (int i = 0; i < array.length; ++i) { + assertEquals(2, array[i].length); + for (int j = 0; j < array[i].length; ++j) { + assertEquals(0x0123456789ABCDEFL, array[i][j]); + } + } + } + @Test public void catchExceptionFromLambda() { try {