diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/JSTypeInference.java b/jso/impl/src/main/java/org/teavm/jso/impl/JSTypeInference.java index 4985a5b49..81a8412b2 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/JSTypeInference.java +++ b/jso/impl/src/main/java/org/teavm/jso/impl/JSTypeInference.java @@ -82,6 +82,9 @@ class JSTypeInference extends BaseTypeInference { @Override protected JSType elementType(JSType jsType) { + if (jsType == JSType.NULL) { + return JSType.NULL; + } return jsType instanceof JSType.ArrayType ? ((JSType.ArrayType) jsType).elementType : JSType.MIXED; } diff --git a/tests/src/test/java/org/teavm/vm/VMTest.java b/tests/src/test/java/org/teavm/vm/VMTest.java index 69f4b72ad..c075b9829 100644 --- a/tests/src/test/java/org/teavm/vm/VMTest.java +++ b/tests/src/test/java/org/teavm/vm/VMTest.java @@ -657,6 +657,20 @@ public class VMTest { assertEquals("ap", callA(new B())); } + @Test + public void typeInferenceForArrayMerge() { + int[][] a = falseBoolean() ? null : array(); + assertEquals(23, a[0][0]); + } + + private boolean falseBoolean() { + return false; + } + + private int[][] array() { + return new int[][] { { 23 } }; + } + private static String callA(A a) { return a.a(); }