[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");
}
@Test
@TestMetadata("whenExpr.kt")
public void testWhenExpr() throws Exception {
runTest("compiler/testData/debug/stepping/whenExpr.kt");
}
@Test
@TestMetadata("whenIsChecks.kt")
public void testWhenIsChecks() throws Exception {
@@ -535,6 +535,12 @@ public class FirPsiSteppingTestGenerated extends AbstractFirPsiSteppingTest {
runTest("compiler/testData/debug/stepping/whenConstant.kt");
}
@Test
@TestMetadata("whenExpr.kt")
public void testWhenExpr() throws Exception {
runTest("compiler/testData/debug/stepping/whenExpr.kt");
}
@Test
@TestMetadata("whenIsChecks.kt")
public void testWhenIsChecks() throws Exception {
@@ -835,22 +835,24 @@ class ExpressionsConverter(
}
val calculatedFirExpression = firExpression ?: buildErrorExpression(
null,
source = null,
ConeSimpleDiagnostic("No expression in condition with expression", DiagnosticKind.Syntax)
)
return if (whenRefWithSubject != null) {
buildEqualityOperatorCall {
source = whenCondition.toFirSourceElement(KtFakeSourceElementKind.WhenCondition)
operation = FirOperation.EQ
argumentList = buildBinaryArgumentList(
buildWhenSubjectExpression {
whenRef = whenRefWithSubject
}, calculatedFirExpression
)
}
} else {
calculatedFirExpression
if (whenRefWithSubject == null) {
return calculatedFirExpression
}
return buildEqualityOperatorCall {
source = whenCondition.toFirSourceElement(KtFakeSourceElementKind.WhenCondition)
operation = FirOperation.EQ
argumentList = buildBinaryArgumentList(
left = buildWhenSubjectExpression {
source = whenCondition.toFirSourceElement()
whenRef = whenRefWithSubject
},
right = calculatedFirExpression
)
}
}
@@ -918,6 +920,7 @@ class ExpressionsConverter(
val subjectExpression = if (whenRefWithSubject != null) {
buildWhenSubjectExpression {
source = whenCondition.toFirSourceElement()
whenRef = whenRefWithSubject
}
} else {