diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt index c44343dce77..f9579c02cd2 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt @@ -1291,13 +1291,13 @@ class Fir2IrVisitor( } private fun FirWhenBranch.toIrWhenBranch(whenExpressionType: ConeKotlinType): IrBranch { - return convertWithOffsets { startOffset, endOffset -> + return convertWithOffsets { startOffset, _ -> val condition = condition val irResult = convertToIrExpression(result).insertImplicitCast(result, result.resolvedType, whenExpressionType) if (condition is FirElseIfTrueCondition) { IrElseBranchImpl(IrConstImpl.boolean(irResult.startOffset, irResult.endOffset, irBuiltIns.booleanType, true), irResult) } else { - IrBranchImpl(startOffset, endOffset, convertToIrExpression(condition), irResult) + IrBranchImpl(startOffset, irResult.endOffset, convertToIrExpression(condition), irResult) } } } diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirLightTreeJvmIrSourceRangesTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirLightTreeJvmIrSourceRangesTestGenerated.java index 8936a6dfcd3..93025489b1b 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirLightTreeJvmIrSourceRangesTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirLightTreeJvmIrSourceRangesTestGenerated.java @@ -67,6 +67,18 @@ public class FirLightTreeJvmIrSourceRangesTestGenerated extends AbstractFirLight runTest("compiler/testData/ir/sourceRanges/kt24258.kt"); } + @Test + @TestMetadata("kt63779.kt") + public void testKt63779() throws Exception { + runTest("compiler/testData/ir/sourceRanges/kt63779.kt"); + } + + @Test + @TestMetadata("kt63779_2.kt") + public void testKt63779_2() throws Exception { + runTest("compiler/testData/ir/sourceRanges/kt63779_2.kt"); + } + @Test @TestMetadata("multiLineCall.kt") public void testMultiLineCall() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirPsiJvmIrSourceRangesTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirPsiJvmIrSourceRangesTestGenerated.java index 3d7160859ca..6f284c04b2d 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirPsiJvmIrSourceRangesTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirPsiJvmIrSourceRangesTestGenerated.java @@ -67,6 +67,18 @@ public class FirPsiJvmIrSourceRangesTestGenerated extends AbstractFirPsiJvmIrSou runTest("compiler/testData/ir/sourceRanges/kt24258.kt"); } + @Test + @TestMetadata("kt63779.kt") + public void testKt63779() throws Exception { + runTest("compiler/testData/ir/sourceRanges/kt63779.kt"); + } + + @Test + @TestMetadata("kt63779_2.kt") + public void testKt63779_2() throws Exception { + runTest("compiler/testData/ir/sourceRanges/kt63779_2.kt"); + } + @Test @TestMetadata("multiLineCall.kt") public void testMultiLineCall() throws Exception { diff --git a/compiler/testData/ir/sourceRanges/kt63779.kt b/compiler/testData/ir/sourceRanges/kt63779.kt new file mode 100644 index 00000000000..59d58902cb9 --- /dev/null +++ b/compiler/testData/ir/sourceRanges/kt63779.kt @@ -0,0 +1,8 @@ +// FIR_IDENTICAL + +fun topLevelMethod(x: Int, y: Int) { + if(x > y) { + } else if(x < y) { + } else { + } +} \ No newline at end of file diff --git a/compiler/testData/ir/sourceRanges/kt63779.txt b/compiler/testData/ir/sourceRanges/kt63779.txt new file mode 100644 index 00000000000..8c384a056d3 --- /dev/null +++ b/compiler/testData/ir/sourceRanges/kt63779.txt @@ -0,0 +1,19 @@ +@0:0..8:0 FILE fqName: fileName:/kt63779.kt + @2:0..7:1 FUN name:topLevelMethod visibility:public modality:FINAL <> (x:kotlin.Int, y:kotlin.Int) returnType:kotlin.Unit + @2:19..25 VALUE_PARAMETER name:x index:0 type:kotlin.Int + @2:27..33 VALUE_PARAMETER name:y index:1 type:kotlin.Int + @2:35..7:1 BLOCK_BODY + @3:4..6:5 WHEN type=kotlin.Unit origin=IF + @3:7..4:5 BRANCH + @3:7..12 CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT + @3:7..8 GET_VAR 'x: kotlin.Int declared in .topLevelMethod' type=kotlin.Int origin=null + @3:11..12 GET_VAR 'y: kotlin.Int declared in .topLevelMethod' type=kotlin.Int origin=null + @3:14..4:5 BLOCK type=kotlin.Unit origin=null + @4:14..5:5 BRANCH + @4:14..19 CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT + @4:14..15 GET_VAR 'x: kotlin.Int declared in .topLevelMethod' type=kotlin.Int origin=null + @4:18..19 GET_VAR 'y: kotlin.Int declared in .topLevelMethod' type=kotlin.Int origin=null + @4:21..5:5 BLOCK type=kotlin.Unit origin=null + @5:11..6:5 BRANCH + @5:11..6:5 CONST Boolean type=kotlin.Boolean value=true + @5:11..6:5 BLOCK type=kotlin.Unit origin=null diff --git a/compiler/testData/ir/sourceRanges/kt63779_2.fir.txt b/compiler/testData/ir/sourceRanges/kt63779_2.fir.txt new file mode 100644 index 00000000000..3b9f8a75a95 --- /dev/null +++ b/compiler/testData/ir/sourceRanges/kt63779_2.fir.txt @@ -0,0 +1,16 @@ +@0:0..5:0 FILE fqName: fileName:/kt63779_2.kt + @1:0..4:1 FUN name:topLevelMethod visibility:public modality:FINAL <> () returnType:kotlin.Unit + @1:21..4:1 BLOCK_BODY + @2:4..13 VAR name:z type:kotlin.Int [var] + @2:12..13 CONST Int type=kotlin.Int value=3 + @3:4..37 WHEN type=kotlin.Unit origin=IF + @3:7..22 BRANCH + @3:7..11 CONST Boolean type=kotlin.Boolean value=true + @3:13..22 BLOCK type=kotlin.Unit origin=null + @3:15..20 SET_VAR 'var z: kotlin.Int [var] declared in .topLevelMethod' type=kotlin.Unit origin=EQ + @3:19..20 CONST Int type=kotlin.Int value=4 + @3:28..37 BRANCH + @3:28..37 CONST Boolean type=kotlin.Boolean value=true + @3:28..37 BLOCK type=kotlin.Unit origin=null + @3:30..35 SET_VAR 'var z: kotlin.Int [var] declared in .topLevelMethod' type=kotlin.Unit origin=EQ + @3:34..35 CONST Int type=kotlin.Int value=5 diff --git a/compiler/testData/ir/sourceRanges/kt63779_2.kt b/compiler/testData/ir/sourceRanges/kt63779_2.kt new file mode 100644 index 00000000000..c5acc0b6c42 --- /dev/null +++ b/compiler/testData/ir/sourceRanges/kt63779_2.kt @@ -0,0 +1,5 @@ +// In this test K2 behaviour is preferable. +fun topLevelMethod() { + var z = 3 + if(true) { z = 4 } else { z = 5 } +} diff --git a/compiler/testData/ir/sourceRanges/kt63779_2.txt b/compiler/testData/ir/sourceRanges/kt63779_2.txt new file mode 100644 index 00000000000..fa07217c518 --- /dev/null +++ b/compiler/testData/ir/sourceRanges/kt63779_2.txt @@ -0,0 +1,16 @@ +@0:0..5:0 FILE fqName: fileName:/kt63779_2.kt + @1:0..4:1 FUN name:topLevelMethod visibility:public modality:FINAL <> () returnType:kotlin.Unit + @1:21..4:1 BLOCK_BODY + @2:8..9 VAR name:z type:kotlin.Int [var] + @2:12..13 CONST Int type=kotlin.Int value=3 + @3:4..37 WHEN type=kotlin.Unit origin=IF + @3:4..37 BRANCH + @3:7..11 CONST Boolean type=kotlin.Boolean value=true + @3:13..22 BLOCK type=kotlin.Unit origin=null + @3:15..16 SET_VAR 'var z: kotlin.Int [var] declared in .topLevelMethod' type=kotlin.Unit origin=EQ + @3:19..20 CONST Int type=kotlin.Int value=4 + @3:4..37 BRANCH + @3:4..37 CONST Boolean type=kotlin.Boolean value=true + @3:28..37 BLOCK type=kotlin.Unit origin=null + @3:30..31 SET_VAR 'var z: kotlin.Int [var] declared in .topLevelMethod' type=kotlin.Unit origin=EQ + @3:34..35 CONST Int type=kotlin.Int value=5 diff --git a/compiler/testData/ir/sourceRanges/this.fir.txt b/compiler/testData/ir/sourceRanges/this.fir.txt index 1147e5e9abc..9c5dc1d0816 100644 --- a/compiler/testData/ir/sourceRanges/this.fir.txt +++ b/compiler/testData/ir/sourceRanges/this.fir.txt @@ -8,7 +8,7 @@ @3:4..46 FIELD PROPERTY_BACKING_FIELD name:maybeThis type:.Klass? visibility:private [final] @3:20..46 EXPRESSION_BODY @3:20..46 WHEN type=.Klass? origin=IF - @3:24..30 BRANCH + @3:24..36 BRANCH @3:24..30 CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ @3:24..25 CONST Int type=kotlin.Int value=1 @3:29..30 CONST Int type=kotlin.Int value=1 diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/ClassicJvmIrSourceRangesTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/ClassicJvmIrSourceRangesTestGenerated.java index 05d5663a1c6..3de9d48d759 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/ClassicJvmIrSourceRangesTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/ClassicJvmIrSourceRangesTestGenerated.java @@ -67,6 +67,18 @@ public class ClassicJvmIrSourceRangesTestGenerated extends AbstractClassicJvmIrS runTest("compiler/testData/ir/sourceRanges/kt24258.kt"); } + @Test + @TestMetadata("kt63779.kt") + public void testKt63779() throws Exception { + runTest("compiler/testData/ir/sourceRanges/kt63779.kt"); + } + + @Test + @TestMetadata("kt63779_2.kt") + public void testKt63779_2() throws Exception { + runTest("compiler/testData/ir/sourceRanges/kt63779_2.kt"); + } + @Test @TestMetadata("multiLineCall.kt") public void testMultiLineCall() throws Exception {