diff --git a/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java b/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java index 9ebbb3aac..8dff00b42 100644 --- a/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java +++ b/core/src/main/java/org/teavm/backend/c/generate/ClassGenerator.java @@ -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); diff --git a/tests/src/test/java/org/teavm/vm/RttiTest.java b/tests/src/test/java/org/teavm/vm/RttiTest.java index d020574af..bef2241b7 100644 --- a/tests/src/test/java/org/teavm/vm/RttiTest.java +++ b/tests/src/test/java/org/teavm/vm/RttiTest.java @@ -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 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);