diff --git a/compiler/testData/codegen/box/reified/reifiedChain.kt b/compiler/testData/codegen/box/reified/reifiedChain.kt new file mode 100644 index 00000000000..476197c805c --- /dev/null +++ b/compiler/testData/codegen/box/reified/reifiedChain.kt @@ -0,0 +1,36 @@ +inline fun Any?.check(): Boolean { + return this is T +} + +inline fun Any?.check2(): Boolean { + return check() +} + + +var log = "" +fun log(a: Any?) { + log += a.toString() + ";" +} + +fun test(a: Any?) { + log(a.check()) + log(a.check()) +} + +fun test2(a: Any?) { + log(a.check2()) + log(a.check2()) +} + +fun box(): String { + test("") + test(null) + test2("") + test2(null) + + if (log != "true;true;false;true;true;true;false;true;") { + return "fail" + } + + return "OK" +} \ No newline at end of file diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 35969ed4628..3217dde5595 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -14540,6 +14540,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("reifiedChain.kt") + public void testReifiedChain() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reified/reifiedChain.kt"); + doTest(fileName); + } + @TestMetadata("reifiedInlineFunOfObject.kt") public void testReifiedInlineFunOfObject() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reified/reifiedInlineFunOfObject.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 1a7e66d27e2..6a75b67f035 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -14540,6 +14540,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("reifiedChain.kt") + public void testReifiedChain() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reified/reifiedChain.kt"); + doTest(fileName); + } + @TestMetadata("reifiedInlineFunOfObject.kt") public void testReifiedInlineFunOfObject() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reified/reifiedInlineFunOfObject.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 97811184785..eeb6cf69cf4 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -19112,6 +19112,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); } + @TestMetadata("reifiedChain.kt") + public void testReifiedChain() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reified/reifiedChain.kt"); + doTest(fileName); + } + @TestMetadata("reifiedInlineFunOfObject.kt") public void testReifiedInlineFunOfObject() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/reified/reifiedInlineFunOfObject.kt"); diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/PatternTranslator.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/PatternTranslator.java index 4f478beb0ac..02644f17671 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/PatternTranslator.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/PatternTranslator.java @@ -138,7 +138,9 @@ public final class PatternTranslator extends AbstractTranslator { public JsExpression getIsTypeCheckCallable(@NotNull KotlinType type) { JsExpression callable = doGetIsTypeCheckCallable(type); - if (isNullableType(type)) { + // If the type is reified, rely on the corresponding is type callable. + // Otherwise make sure that passing null yields true + if (!isReifiedTypeParameter(type) && isNullableType(type)) { return namer().orNull(callable); }