From 7058a195b70c49b933f037f14ca7cce22a0c5a70 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Thu, 1 Apr 2021 12:05:18 +0300 Subject: [PATCH] JS: fix class of object created by multianewarray instruction --- .../javascript/rendering/StatementRenderer.java | 2 +- tests/src/test/java/org/teavm/vm/VMTest.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/teavm/backend/javascript/rendering/StatementRenderer.java b/core/src/main/java/org/teavm/backend/javascript/rendering/StatementRenderer.java index f34978a08..62f23432f 100644 --- a/core/src/main/java/org/teavm/backend/javascript/rendering/StatementRenderer.java +++ b/core/src/main/java/org/teavm/backend/javascript/rendering/StatementRenderer.java @@ -1479,7 +1479,7 @@ public class StatementRenderer implements ExprVisitor, StatementVisitor { } } else { writer.append("$rt_createMultiArray("); - context.typeToClsString(writer, expr.getType()); + context.typeToClsString(writer, type); writer.append(",").ws(); } writer.append("["); diff --git a/tests/src/test/java/org/teavm/vm/VMTest.java b/tests/src/test/java/org/teavm/vm/VMTest.java index c1b86ed63..455ac39c7 100644 --- a/tests/src/test/java/org/teavm/vm/VMTest.java +++ b/tests/src/test/java/org/teavm/vm/VMTest.java @@ -579,4 +579,16 @@ public class VMTest { array.wait(1); } } + + @Test + public void castMultiArray() { + Object o = new String[0][0]; + assertEquals(0, ((String[][]) o).length); + o = new String[0][]; + assertEquals(0, ((String[][]) o).length); + o = new int[0][0]; + assertEquals(0, ((int[][]) o).length); + o = new int[0][]; + assertEquals(0, ((int[][]) o).length); + } } \ No newline at end of file