[FIR LT] Add proper source for when with subject

#KT-56982 Fixed
This commit is contained in:
Ivan Kylchik
2023-03-20 17:43:41 +01:00
committed by Space Team
parent 45e78455b2
commit e4591d7af9
8 changed files with 82 additions and 13 deletions
@@ -535,6 +535,12 @@ public class FirLightTreeSteppingTestGenerated extends AbstractFirLightTreeStepp
runTest("compiler/testData/debug/stepping/whenConstant.kt"); runTest("compiler/testData/debug/stepping/whenConstant.kt");
} }
@Test
@TestMetadata("whenExpr.kt")
public void testWhenExpr() throws Exception {
runTest("compiler/testData/debug/stepping/whenExpr.kt");
}
@Test @Test
@TestMetadata("whenIsChecks.kt") @TestMetadata("whenIsChecks.kt")
public void testWhenIsChecks() throws Exception { public void testWhenIsChecks() throws Exception {
@@ -535,6 +535,12 @@ public class FirPsiSteppingTestGenerated extends AbstractFirPsiSteppingTest {
runTest("compiler/testData/debug/stepping/whenConstant.kt"); runTest("compiler/testData/debug/stepping/whenConstant.kt");
} }
@Test
@TestMetadata("whenExpr.kt")
public void testWhenExpr() throws Exception {
runTest("compiler/testData/debug/stepping/whenExpr.kt");
}
@Test @Test
@TestMetadata("whenIsChecks.kt") @TestMetadata("whenIsChecks.kt")
public void testWhenIsChecks() throws Exception { public void testWhenIsChecks() throws Exception {
@@ -835,23 +835,25 @@ class ExpressionsConverter(
} }
val calculatedFirExpression = firExpression ?: buildErrorExpression( val calculatedFirExpression = firExpression ?: buildErrorExpression(
null, source = null,
ConeSimpleDiagnostic("No expression in condition with expression", DiagnosticKind.Syntax) ConeSimpleDiagnostic("No expression in condition with expression", DiagnosticKind.Syntax)
) )
return if (whenRefWithSubject != null) { if (whenRefWithSubject == null) {
buildEqualityOperatorCall { return calculatedFirExpression
}
return buildEqualityOperatorCall {
source = whenCondition.toFirSourceElement(KtFakeSourceElementKind.WhenCondition) source = whenCondition.toFirSourceElement(KtFakeSourceElementKind.WhenCondition)
operation = FirOperation.EQ operation = FirOperation.EQ
argumentList = buildBinaryArgumentList( argumentList = buildBinaryArgumentList(
buildWhenSubjectExpression { left = buildWhenSubjectExpression {
source = whenCondition.toFirSourceElement()
whenRef = whenRefWithSubject whenRef = whenRefWithSubject
}, calculatedFirExpression },
right = calculatedFirExpression
) )
} }
} else {
calculatedFirExpression
}
} }
private fun convertWhenConditionInRange( private fun convertWhenConditionInRange(
@@ -918,6 +920,7 @@ class ExpressionsConverter(
val subjectExpression = if (whenRefWithSubject != null) { val subjectExpression = if (whenRefWithSubject != null) {
buildWhenSubjectExpression { buildWhenSubjectExpression {
source = whenCondition.toFirSourceElement()
whenRef = whenRefWithSubject whenRef = whenRefWithSubject
} }
} else { } else {
+30
View File
@@ -0,0 +1,30 @@
// FILE: test.kt
fun box() {
val a: Int? = 3
when (a) {
1 -> {
1
}
2 -> {
2
}
else -> {
0
}
}
}
// EXPECTATIONS JVM JVM_IR
// test.kt:4 box
// test.kt:5 box
// test.kt:6 box
// test.kt:9 box
// test.kt:13 box
// test.kt:16 box
// EXPECTATIONS JS_IR
// test.kt:4 box
// test.kt:5 box
// test.kt:5 box
// test.kt:16 box
@@ -535,6 +535,12 @@ public class IrSteppingWithBytecodeInlinerTestGenerated extends AbstractIrSteppi
runTest("compiler/testData/debug/stepping/whenConstant.kt"); runTest("compiler/testData/debug/stepping/whenConstant.kt");
} }
@Test
@TestMetadata("whenExpr.kt")
public void testWhenExpr() throws Exception {
runTest("compiler/testData/debug/stepping/whenExpr.kt");
}
@Test @Test
@TestMetadata("whenIsChecks.kt") @TestMetadata("whenIsChecks.kt")
public void testWhenIsChecks() throws Exception { public void testWhenIsChecks() throws Exception {
@@ -535,6 +535,12 @@ public class IrSteppingWithIrInlinerTestGenerated extends AbstractIrSteppingWith
runTest("compiler/testData/debug/stepping/whenConstant.kt"); runTest("compiler/testData/debug/stepping/whenConstant.kt");
} }
@Test
@TestMetadata("whenExpr.kt")
public void testWhenExpr() throws Exception {
runTest("compiler/testData/debug/stepping/whenExpr.kt");
}
@Test @Test
@TestMetadata("whenIsChecks.kt") @TestMetadata("whenIsChecks.kt")
public void testWhenIsChecks() throws Exception { public void testWhenIsChecks() throws Exception {
@@ -535,6 +535,12 @@ public class SteppingTestGenerated extends AbstractSteppingTest {
runTest("compiler/testData/debug/stepping/whenConstant.kt"); runTest("compiler/testData/debug/stepping/whenConstant.kt");
} }
@Test
@TestMetadata("whenExpr.kt")
public void testWhenExpr() throws Exception {
runTest("compiler/testData/debug/stepping/whenExpr.kt");
}
@Test @Test
@TestMetadata("whenIsChecks.kt") @TestMetadata("whenIsChecks.kt")
public void testWhenIsChecks() throws Exception { public void testWhenIsChecks() throws Exception {
@@ -535,6 +535,12 @@ public class IrJsSteppingTestGenerated extends AbstractIrJsSteppingTest {
runTest("compiler/testData/debug/stepping/whenConstant.kt"); runTest("compiler/testData/debug/stepping/whenConstant.kt");
} }
@Test
@TestMetadata("whenExpr.kt")
public void testWhenExpr() throws Exception {
runTest("compiler/testData/debug/stepping/whenExpr.kt");
}
@Test @Test
@TestMetadata("whenIsChecks.kt") @TestMetadata("whenIsChecks.kt")
public void testWhenIsChecks() throws Exception { public void testWhenIsChecks() throws Exception {