From bec434d5341911e900a69add80617f7522545a04 Mon Sep 17 00:00:00 2001 From: Artem Kobzar Date: Tue, 14 Nov 2023 10:40:07 +0000 Subject: [PATCH] [K/JS] Save nullability from the original type of value parameters ^KT-63013 Fixed --- .../backend/common/lower/inline/FunctionInlining.kt | 2 +- .../kotlin/js/test/fir/FirJsBoxTestGenerated.java | 6 ++++++ .../kotlin/js/test/fir/FirJsES6BoxTestGenerated.java | 6 ++++++ .../kotlin/js/test/ir/IrBoxJsES6TestGenerated.java | 6 ++++++ .../kotlin/js/test/ir/IrBoxJsTestGenerated.java | 6 ++++++ .../testData/box/inline/requireNotNull.kt | 11 +++++++++++ 6 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 js/js.translator/testData/box/inline/requireNotNull.kt diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/inline/FunctionInlining.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/inline/FunctionInlining.kt index 515b7687c60..5d3e5126481 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/inline/FunctionInlining.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/inline/FunctionInlining.kt @@ -763,7 +763,7 @@ class FunctionInlining( // in case of recursive call, we can get a situation there the same type parameter will be mapped on different type arguments. // (see compiler/testData/codegen/boxInline/complex/use.kt test file) val newTypeParameter = copy.typeParameters[typeClassifier.index].defaultType.substituteSuperTypes() - return if (useTypeParameterUpperBound) typeClassifier.firstRealUpperBound() else newTypeParameter + return if (useTypeParameterUpperBound) typeClassifier.firstRealUpperBound().mergeNullability(type) else newTypeParameter } return when (this) { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java index 6cdbdb1b7bb..1400a8541a8 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsBoxTestGenerated.java @@ -5896,6 +5896,12 @@ public class FirJsBoxTestGenerated extends AbstractFirJsBoxTest { runTest("js/js.translator/testData/box/inline/recursiveDependency.kt"); } + @Test + @TestMetadata("requireNotNull.kt") + public void testRequireNotNull() throws Exception { + runTest("js/js.translator/testData/box/inline/requireNotNull.kt"); + } + @Test @TestMetadata("rootConstructor.kt") public void testRootConstructor() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6BoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6BoxTestGenerated.java index f9ebea9dfcf..59575bfa7fc 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6BoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsES6BoxTestGenerated.java @@ -6002,6 +6002,12 @@ public class FirJsES6BoxTestGenerated extends AbstractFirJsES6BoxTest { runTest("js/js.translator/testData/box/inline/recursiveDependency.kt"); } + @Test + @TestMetadata("requireNotNull.kt") + public void testRequireNotNull() throws Exception { + runTest("js/js.translator/testData/box/inline/requireNotNull.kt"); + } + @Test @TestMetadata("rootConstructor.kt") public void testRootConstructor() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsES6TestGenerated.java index b7f9e9ea02e..da66c52da13 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsES6TestGenerated.java @@ -6002,6 +6002,12 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test { runTest("js/js.translator/testData/box/inline/recursiveDependency.kt"); } + @Test + @TestMetadata("requireNotNull.kt") + public void testRequireNotNull() throws Exception { + runTest("js/js.translator/testData/box/inline/requireNotNull.kt"); + } + @Test @TestMetadata("rootConstructor.kt") public void testRootConstructor() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java index a6255394032..4f6d26d4e8e 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java @@ -5896,6 +5896,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { runTest("js/js.translator/testData/box/inline/recursiveDependency.kt"); } + @Test + @TestMetadata("requireNotNull.kt") + public void testRequireNotNull() throws Exception { + runTest("js/js.translator/testData/box/inline/requireNotNull.kt"); + } + @Test @TestMetadata("rootConstructor.kt") public void testRootConstructor() throws Exception { diff --git a/js/js.translator/testData/box/inline/requireNotNull.kt b/js/js.translator/testData/box/inline/requireNotNull.kt new file mode 100644 index 00000000000..8330541a64f --- /dev/null +++ b/js/js.translator/testData/box/inline/requireNotNull.kt @@ -0,0 +1,11 @@ +// WITH_STDLIB +// EXPECTED_REACHABLE_NODES: 1283 +package foo + +fun box(): String { + val foo: Char? = 'c' + requireNotNull(foo) { "Fail 1" } + val bar: Char? = null + requireNotNull(bar) { return "OK" } + return "Fail 2" +}