jso: fix incorrect type inference for array element types

Fix #937
This commit is contained in:
Alexey Andreev 2024-08-12 17:32:54 +02:00
parent 6af7250e3b
commit 065aef581d
2 changed files with 17 additions and 0 deletions

View File

@ -82,6 +82,9 @@ class JSTypeInference extends BaseTypeInference<JSType> {
@Override @Override
protected JSType elementType(JSType jsType) { protected JSType elementType(JSType jsType) {
if (jsType == JSType.NULL) {
return JSType.NULL;
}
return jsType instanceof JSType.ArrayType ? ((JSType.ArrayType) jsType).elementType : JSType.MIXED; return jsType instanceof JSType.ArrayType ? ((JSType.ArrayType) jsType).elementType : JSType.MIXED;
} }

View File

@ -657,6 +657,20 @@ public class VMTest {
assertEquals("ap", callA(new B())); 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) { private static String callA(A a) {
return a.a(); return a.a();
} }