C: don't treat primitives as subtypes of Object. Fix #411

This commit is contained in:
Alexey Andreev 2019-08-07 13:45:40 +03:00
parent 2e27a3c218
commit e16ba8a6ca
2 changed files with 24 additions and 1 deletions

View File

@ -663,7 +663,7 @@ public class ClassGenerator {
itemTypeExpr = "NULL";
} else {
parent = "NULL";
tag = 0;
tag = Integer.MAX_VALUE;
sizeExpr = "sizeof(" + CodeWriter.strictTypeAsString(type) + ")";
flags |= RuntimeClass.PRIMITIVE;
flags = ClassGeneratorUtil.applyPrimitiveFlags(flags, type);

View File

@ -15,7 +15,11 @@
*/
package org.teavm.vm;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.teavm.junit.TeaVMTestRunner;
@ -33,6 +37,25 @@ public class RttiTest {
checkImplements(new G(), true, true, false);
}
@Test
public void objectIsNotSupertypeOfPrimitive() {
assertFalse(Object.class.isAssignableFrom(int.class));
}
@Test
public void instanceOfObjectArray() {
List<Object> list = new ArrayList<>();
list.add("123");
list.add(new Object[0]);
list.add(new String[0]);
list.add(new int[0]);
StringBuilder sb = new StringBuilder();
for (Object item : list) {
sb.append(item instanceof Object[] ? 't' : 'f');
}
assertEquals("fttf", sb.toString());
}
private void checkImplements(Object o, boolean i, boolean j, boolean k) {
assertTrue(predicate(o, i, "I"), !i ^ o instanceof I);
assertTrue(predicate(o, j, "J"), !j ^ o instanceof J);