mirror of
https://github.com/konsoletyper/teavm.git
synced 2024-11-27 01:30:35 +08:00
C: don't treat primitives as subtypes of Object. Fix #411
This commit is contained in:
parent
2e27a3c218
commit
e16ba8a6ca
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user