Check that subject expression is evaluated only once
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
||||
// !LANGUAGE: +VariableDeclarationInWhenSubject
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
var effectCount = 0
|
||||
|
||||
fun withSideEffect(): Any {
|
||||
effectCount++
|
||||
return 42
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
when (val y = withSideEffect()) {
|
||||
1 -> throw AssertionError()
|
||||
"" -> throw AssertionError()
|
||||
is String -> throw AssertionError()
|
||||
42 -> {}
|
||||
}
|
||||
|
||||
if (effectCount != 1) throw AssertionError("effectCount=$effectCount")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Generated
+5
@@ -21708,6 +21708,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/when/whenSubjectVariable/sparseIntSwitchWithSubjectVariable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("subjectExpressionIsEvaluatedOnce.kt")
|
||||
public void testSubjectExpressionIsEvaluatedOnce() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/whenSubjectVariable/subjectExpressionIsEvaluatedOnce.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("whenByEnum.kt")
|
||||
public void testWhenByEnum() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/whenSubjectVariable/whenByEnum.kt");
|
||||
|
||||
+5
@@ -21708,6 +21708,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/when/whenSubjectVariable/sparseIntSwitchWithSubjectVariable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("subjectExpressionIsEvaluatedOnce.kt")
|
||||
public void testSubjectExpressionIsEvaluatedOnce() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/whenSubjectVariable/subjectExpressionIsEvaluatedOnce.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("whenByEnum.kt")
|
||||
public void testWhenByEnum() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/whenSubjectVariable/whenByEnum.kt");
|
||||
|
||||
+5
@@ -21708,6 +21708,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/when/whenSubjectVariable/sparseIntSwitchWithSubjectVariable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("subjectExpressionIsEvaluatedOnce.kt")
|
||||
public void testSubjectExpressionIsEvaluatedOnce() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/whenSubjectVariable/subjectExpressionIsEvaluatedOnce.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("whenByEnum.kt")
|
||||
public void testWhenByEnum() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/whenSubjectVariable/whenByEnum.kt");
|
||||
|
||||
+5
@@ -20723,6 +20723,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/when/whenSubjectVariable/sparseIntSwitchWithSubjectVariable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("subjectExpressionIsEvaluatedOnce.kt")
|
||||
public void testSubjectExpressionIsEvaluatedOnce() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/whenSubjectVariable/subjectExpressionIsEvaluatedOnce.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("whenByEnum.kt")
|
||||
public void testWhenByEnum() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/whenSubjectVariable/whenByEnum.kt");
|
||||
|
||||
+5
@@ -19601,6 +19601,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/when/whenSubjectVariable/sparseIntSwitchWithSubjectVariable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("subjectExpressionIsEvaluatedOnce.kt")
|
||||
public void testSubjectExpressionIsEvaluatedOnce() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/whenSubjectVariable/subjectExpressionIsEvaluatedOnce.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("whenByEnum.kt")
|
||||
public void testWhenByEnum() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/when/whenSubjectVariable/whenByEnum.kt");
|
||||
|
||||
Reference in New Issue
Block a user