From b5b361bb091849b3a63238ca880af61878cb9ad9 Mon Sep 17 00:00:00 2001 From: Mark Punzalan Date: Fri, 8 May 2020 23:34:52 -0700 Subject: [PATCH] Add tests for nullable loop variable in for-loop over unsigned progression. --- .../ir/FirBlackBoxCodegenTestGenerated.java | 28 +++++++++++++++++++ .../progressionExpression.kt | 18 ++++++++++++ .../nullableLoopParameter/rangeExpression.kt | 18 ++++++++++++ .../nullableLoopParameter/rangeLiteral.kt | 17 +++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 28 +++++++++++++++++++ .../LightAnalysisModeTestGenerated.java | 28 +++++++++++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 28 +++++++++++++++++++ .../IrJsCodegenBoxTestGenerated.java | 28 +++++++++++++++++++ .../semantics/JsCodegenBoxTestGenerated.java | 28 +++++++++++++++++++ 9 files changed, 221 insertions(+) create mode 100644 compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/progressionExpression.kt create mode 100644 compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/rangeExpression.kt create mode 100644 compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/rangeLiteral.kt diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index f7747f49698..0c51ec004ad 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -24419,6 +24419,34 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/ranges/unsigned/literal/simpleSteppedRange.kt"); } } + + @TestMetadata("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class NullableLoopParameter extends AbstractFirBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTestWithCustomIgnoreDirective(this::doTest, TargetBackend.JVM_IR, testDataFilePath, "// IGNORE_BACKEND_FIR: "); + } + + public void testAllFilesPresentInNullableLoopParameter() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @TestMetadata("progressionExpression.kt") + public void testProgressionExpression() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/progressionExpression.kt"); + } + + @TestMetadata("rangeExpression.kt") + public void testRangeExpression() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/rangeExpression.kt"); + } + + @TestMetadata("rangeLiteral.kt") + public void testRangeLiteral() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/rangeLiteral.kt"); + } + } } } diff --git a/compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/progressionExpression.kt b/compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/progressionExpression.kt new file mode 100644 index 00000000000..c02d0122678 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/progressionExpression.kt @@ -0,0 +1,18 @@ +// IGNORE_BACKEND: JVM +// See KT-38833: Runtime exception is "java.lang.ClassCastException: java.lang.Integer cannot be cast to kotlin.UInt" + +// WITH_RUNTIME +// KJS_WITH_FULL_RUNTIME + +fun box(): String { + var result = 0u + val uIntRange: UIntProgression = 1u..3u + for (i: UInt? in uIntRange) { + result = sum(result, i) + } + return if (result == 6u) "OK" else "fail: $result" +} + +fun sum(i: UInt, z: UInt?): UInt { + return i + z!! +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/rangeExpression.kt b/compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/rangeExpression.kt new file mode 100644 index 00000000000..e200d232a33 --- /dev/null +++ b/compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/rangeExpression.kt @@ -0,0 +1,18 @@ +// IGNORE_BACKEND: JVM +// See KT-38833: Runtime exception is "java.lang.ClassCastException: java.lang.Integer cannot be cast to kotlin.UInt" + +// WITH_RUNTIME +// KJS_WITH_FULL_RUNTIME + +fun box(): String { + var result = 0u + val uIntRange = 1u..3u + for (i: UInt? in uIntRange) { + result = sum(result, i) + } + return if (result == 6u) "OK" else "fail: $result" +} + +fun sum(i: UInt, z: UInt?): UInt { + return i + z!! +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/rangeLiteral.kt b/compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/rangeLiteral.kt new file mode 100644 index 00000000000..f131cbf25bc --- /dev/null +++ b/compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/rangeLiteral.kt @@ -0,0 +1,17 @@ +// IGNORE_BACKEND: JVM +// See KT-38833: Runtime exception is "java.lang.ClassCastException: java.lang.Integer cannot be cast to kotlin.UInt" + +// WITH_RUNTIME +// KJS_WITH_FULL_RUNTIME + +fun box(): String { + var result = 0u + for (i: UInt? in 1u..3u) { + result = sum(result, i) + } + return if (result == 6u) "OK" else "fail: $result" +} + +fun sum(i: UInt, z: UInt?): UInt { + return i + z!! +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 65af6e070b5..9b9896a52e7 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -26005,6 +26005,34 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/ranges/unsigned/literal/simpleSteppedRange.kt"); } } + + @TestMetadata("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class NullableLoopParameter extends AbstractBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInNullableLoopParameter() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); + } + + @TestMetadata("progressionExpression.kt") + public void testProgressionExpression() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/progressionExpression.kt"); + } + + @TestMetadata("rangeExpression.kt") + public void testRangeExpression() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/rangeExpression.kt"); + } + + @TestMetadata("rangeLiteral.kt") + public void testRangeLiteral() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/rangeLiteral.kt"); + } + } } } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 2e07de62225..4b00adcb5f8 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -23639,6 +23639,34 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/ranges/unsigned/literal/simpleSteppedRange.kt"); } } + + @TestMetadata("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class NullableLoopParameter extends AbstractLightAnalysisModeTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInNullableLoopParameter() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); + } + + @TestMetadata("progressionExpression.kt") + public void testProgressionExpression() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/progressionExpression.kt"); + } + + @TestMetadata("rangeExpression.kt") + public void testRangeExpression() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/rangeExpression.kt"); + } + + @TestMetadata("rangeLiteral.kt") + public void testRangeLiteral() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/rangeLiteral.kt"); + } + } } } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 026193ac716..4d47782ae73 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -24419,6 +24419,34 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/ranges/unsigned/literal/simpleSteppedRange.kt"); } } + + @TestMetadata("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class NullableLoopParameter extends AbstractIrBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath); + } + + public void testAllFilesPresentInNullableLoopParameter() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @TestMetadata("progressionExpression.kt") + public void testProgressionExpression() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/progressionExpression.kt"); + } + + @TestMetadata("rangeExpression.kt") + public void testRangeExpression() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/rangeExpression.kt"); + } + + @TestMetadata("rangeLiteral.kt") + public void testRangeLiteral() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/rangeLiteral.kt"); + } + } } } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index c3159028832..c69ac957b58 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -20820,6 +20820,34 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/ranges/unsigned/literal/simpleSteppedRange.kt"); } } + + @TestMetadata("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class NullableLoopParameter extends AbstractIrJsCodegenBoxTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); + } + + public void testAllFilesPresentInNullableLoopParameter() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @TestMetadata("progressionExpression.kt") + public void testProgressionExpression() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/progressionExpression.kt"); + } + + @TestMetadata("rangeExpression.kt") + public void testRangeExpression() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/rangeExpression.kt"); + } + + @TestMetadata("rangeLiteral.kt") + public void testRangeLiteral() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/rangeLiteral.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 71ecbb85ab7..c105bb1199e 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 @@ -20835,6 +20835,34 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/ranges/unsigned/literal/simpleSteppedRange.kt"); } } + + @TestMetadata("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class NullableLoopParameter extends AbstractJsCodegenBoxTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath); + } + + public void testAllFilesPresentInNullableLoopParameter() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); + } + + @TestMetadata("progressionExpression.kt") + public void testProgressionExpression() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/progressionExpression.kt"); + } + + @TestMetadata("rangeExpression.kt") + public void testRangeExpression() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/rangeExpression.kt"); + } + + @TestMetadata("rangeLiteral.kt") + public void testRangeLiteral() throws Exception { + runTest("compiler/testData/codegen/box/ranges/unsigned/nullableLoopParameter/rangeLiteral.kt"); + } + } } }