diff --git a/compiler/testData/codegen/box/checkcastOptimization/kt19246.kt b/compiler/testData/codegen/box/checkcastOptimization/kt19246.kt new file mode 100644 index 00000000000..7fce122da6a --- /dev/null +++ b/compiler/testData/codegen/box/checkcastOptimization/kt19246.kt @@ -0,0 +1,19 @@ +// WITH_RUNTIME + +enum class ResultType constructor(val reason: String) { + SOMETHING("123"), + OK("OK"), + UNKNOWN("FAIL"); + + companion object { + fun getByVal(reason: String): ResultType { + return ResultType.values().firstOrDefault({ it.reason == reason }, UNKNOWN) + } + } +} + +inline fun Array.firstOrDefault(predicate: (T) -> Boolean, default: T): T { + return firstOrNull(predicate) ?: default +} + +fun box(): String = ResultType.getByVal("OK").reason 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 90d097e1832..19e28ca14eb 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 @@ -2722,6 +2722,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/checkcastOptimization/kt19128.kt"); doTest(fileName); } + + @TestMetadata("kt19246.kt") + public void testKt19246() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/checkcastOptimization/kt19246.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/codegen/box/classLiteral") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 2380cc8566c..34a6fa678df 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -2722,6 +2722,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/checkcastOptimization/kt19128.kt"); doTest(fileName); } + + @TestMetadata("kt19246.kt") + public void testKt19246() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/checkcastOptimization/kt19246.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/codegen/box/classLiteral") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index e1ed00b2a8f..d91f412f796 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -2722,6 +2722,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/checkcastOptimization/kt19128.kt"); doTest(fileName); } + + @TestMetadata("kt19246.kt") + public void testKt19246() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/checkcastOptimization/kt19246.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/codegen/box/classLiteral") 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 11b530cae75..ff2df8c9164 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 @@ -3274,6 +3274,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/checkcastOptimization/kt19128.kt"); doTest(fileName); } + + @TestMetadata("kt19246.kt") + public void testKt19246() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/checkcastOptimization/kt19246.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/codegen/box/classLiteral")