[JVM_IR] Properly handle inlined local var located in regenerated object
#KT-58778
This commit is contained in:
+12
@@ -67,6 +67,12 @@ public class FirLightTreeLocalVariableTestGenerated extends AbstractFirLightTree
|
||||
runTest("compiler/testData/debug/localVariables/forLoopMultiline.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inlineFunInObject.kt")
|
||||
public void testInlineFunInObject() throws Exception {
|
||||
runTest("compiler/testData/debug/localVariables/inlineFunInObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inlineProperty.kt")
|
||||
public void testInlineProperty() throws Exception {
|
||||
@@ -79,6 +85,12 @@ public class FirLightTreeLocalVariableTestGenerated extends AbstractFirLightTree
|
||||
runTest("compiler/testData/debug/localVariables/jvmOverloads.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaInObject.kt")
|
||||
public void testLambdaInObject() throws Exception {
|
||||
runTest("compiler/testData/debug/localVariables/lambdaInObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaWithLambdaParameter.kt")
|
||||
public void testLambdaWithLambdaParameter() throws Exception {
|
||||
|
||||
+12
@@ -67,6 +67,12 @@ public class FirPsiLocalVariableTestGenerated extends AbstractFirPsiLocalVariabl
|
||||
runTest("compiler/testData/debug/localVariables/forLoopMultiline.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inlineFunInObject.kt")
|
||||
public void testInlineFunInObject() throws Exception {
|
||||
runTest("compiler/testData/debug/localVariables/inlineFunInObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inlineProperty.kt")
|
||||
public void testInlineProperty() throws Exception {
|
||||
@@ -79,6 +85,12 @@ public class FirPsiLocalVariableTestGenerated extends AbstractFirPsiLocalVariabl
|
||||
runTest("compiler/testData/debug/localVariables/jvmOverloads.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaInObject.kt")
|
||||
public void testLambdaInObject() throws Exception {
|
||||
runTest("compiler/testData/debug/localVariables/lambdaInObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaWithLambdaParameter.kt")
|
||||
public void testLambdaWithLambdaParameter() throws Exception {
|
||||
|
||||
+10
-10
@@ -422,8 +422,16 @@ class ExpressionCodegen(
|
||||
}
|
||||
}
|
||||
|
||||
if (expression is IrInlinedFunctionBlock && expression.isFunctionInlining()) {
|
||||
markLineNumberAfterInlineIfNeeded(isInsideCondition)
|
||||
if (expression is IrInlinedFunctionBlock) {
|
||||
// This block must be executed after `writeLocalVariablesInTable`
|
||||
if (expression.isFunctionInlining()) {
|
||||
val callLineNumber = lineNumberMapper.getLineNumberForOffset(expression.inlineCall.startOffset)
|
||||
// takeUnless is required to avoid markLineNumberAfterInlineIfNeeded for inline only
|
||||
lastLineNumber = callLineNumber.takeUnless { noLineNumberScope } ?: -1
|
||||
markLineNumberAfterInlineIfNeeded(isInsideCondition)
|
||||
} else {
|
||||
lineNumberMapper.setUpAdditionalLineNumbersAfterLambdaInlining(expression)
|
||||
}
|
||||
}
|
||||
|
||||
if (isSynthesizedInitBlock) {
|
||||
@@ -482,7 +490,6 @@ class ExpressionCodegen(
|
||||
private fun visitInlinedFunctionBlock(inlinedBlock: IrInlinedFunctionBlock, data: BlockInfo): PromisedValue {
|
||||
val inlineCall = inlinedBlock.inlineCall
|
||||
val callee = inlinedBlock.inlineDeclaration as? IrFunction
|
||||
val callLineNumber = lineNumberMapper.getLineNumberForOffset(inlineCall.startOffset)
|
||||
|
||||
// 1. Evaluate NON DEFAULT arguments from inline function call
|
||||
inlinedBlock.getNonDefaultAdditionalStatementsFromInlinedBlock().forEach { exp ->
|
||||
@@ -539,13 +546,6 @@ class ExpressionCodegen(
|
||||
|
||||
lineNumberMapper.dropCurrentSmap()
|
||||
|
||||
if (inlinedBlock.isLambdaInlining()) {
|
||||
lineNumberMapper.setUpAdditionalLineNumbersAfterLambdaInlining(inlinedBlock)
|
||||
} else {
|
||||
// takeUnless is required to avoid markLineNumberAfterInlineIfNeeded for inline only
|
||||
lastLineNumber = callLineNumber.takeUnless { noLineNumberScope } ?: -1
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
+8
@@ -123,6 +123,14 @@ private class LocalVariablesProcessor : IrElementVisitor<Unit, LocalVariablesPro
|
||||
element.acceptChildren(this, data)
|
||||
}
|
||||
|
||||
override fun visitClass(declaration: IrClass, data: Data) {
|
||||
if (declaration.originalBeforeInline != null) {
|
||||
// Don't take into account regenerated classes
|
||||
return super.visitClass(declaration, data.copy(processingOriginalDeclarations = false))
|
||||
}
|
||||
super.visitClass(declaration, data)
|
||||
}
|
||||
|
||||
override fun visitBlock(expression: IrBlock, data: Data) {
|
||||
if (expression !is IrInlinedFunctionBlock) {
|
||||
return super.visitBlock(expression, data)
|
||||
|
||||
Vendored
-2
@@ -1,5 +1,3 @@
|
||||
// IGNORE_INLINER: IR
|
||||
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
// FILE: test.kt
|
||||
inline fun foo(block: () -> Unit) {
|
||||
object {
|
||||
fun baz(param: Int) {
|
||||
val a = 1
|
||||
inlineCall {
|
||||
val f = 6
|
||||
}
|
||||
}
|
||||
}.baz(5)
|
||||
}
|
||||
|
||||
inline fun bar(crossinline block: () -> Unit) {
|
||||
object {
|
||||
fun baz(param: Int) {
|
||||
val b = 2
|
||||
block()
|
||||
inlineCall {
|
||||
val g = 7
|
||||
}
|
||||
}
|
||||
}.baz(6)
|
||||
}
|
||||
|
||||
inline fun inlineCall(block: () -> Unit) {
|
||||
val e = 5
|
||||
block()
|
||||
}
|
||||
|
||||
fun box() {
|
||||
foo() {
|
||||
val c = 3
|
||||
}
|
||||
|
||||
bar() {
|
||||
val d = 4
|
||||
}
|
||||
}
|
||||
|
||||
// EXPECTATIONS JVM JVM_IR
|
||||
// test.kt:31 box:
|
||||
// test.kt:3 box: $i$f$foo:int=0:int
|
||||
// test.kt:3 <init>:
|
||||
// test.kt:10 box: $i$f$foo:int=0:int
|
||||
// test.kt:5 baz: param:int=5:int
|
||||
// test.kt:6 baz: param:int=5:int, a:int=1:int
|
||||
// test.kt:26 baz: param:int=5:int, a:int=1:int, $i$f$inlineCall:int=0:int
|
||||
// test.kt:27 baz: param:int=5:int, a:int=1:int, $i$f$inlineCall:int=0:int, e$iv:int=5:int
|
||||
// test.kt:7 baz: param:int=5:int, a:int=1:int, $i$f$inlineCall:int=0:int, e$iv:int=5:int, $i$a$-inlineCall-TestKt$foo$1$baz$1:int=0:int
|
||||
// EXPECTATIONS JVM_IR
|
||||
// test.kt:8 baz: param:int=5:int, a:int=1:int, $i$f$inlineCall:int=0:int, e$iv:int=5:int, $i$a$-inlineCall-TestKt$foo$1$baz$1:int=0:int, f:int=6:int
|
||||
// EXPECTATIONS JVM
|
||||
// test.kt:8 baz: param:int=5:int, a:int=1:int, $i$f$inlineCall:int=0:int, e$iv:int=5:int, $i$a$-inlineCall-TestKt$foo$1$baz$1:int=0:int
|
||||
// EXPECTATIONS JVM JVM_IR
|
||||
// test.kt:27 baz: param:int=5:int, a:int=1:int, $i$f$inlineCall:int=0:int, e$iv:int=5:int
|
||||
// test.kt:28 baz: param:int=5:int, a:int=1:int, $i$f$inlineCall:int=0:int, e$iv:int=5:int
|
||||
// test.kt:9 baz: param:int=5:int, a:int=1:int
|
||||
// test.kt:11 box: $i$f$foo:int=0:int
|
||||
// test.kt:35 box:
|
||||
// test.kt:14 box: $i$f$bar:int=0:int
|
||||
// test.kt:14 <init>:
|
||||
// test.kt:22 box: $i$f$bar:int=0:int
|
||||
// test.kt:16 baz: param:int=6:int
|
||||
// test.kt:17 baz: param:int=6:int, b:int=2:int
|
||||
// test.kt:36 baz: param:int=6:int, b:int=2:int, $i$a$-bar-TestKt$box$2:int=0:int
|
||||
// EXPECTATIONS JVM_IR
|
||||
// test.kt:37 baz: param:int=6:int, b:int=2:int, $i$a$-bar-TestKt$box$2:int=0:int, d:int=4:int
|
||||
// EXPECTATIONS JVM
|
||||
// test.kt:37 baz: param:int=6:int, b:int=2:int, $i$a$-bar-TestKt$box$2:int=0:int
|
||||
// EXPECTATIONS JVM JVM_IR
|
||||
// test.kt:17 baz: param:int=6:int, b:int=2:int
|
||||
// test.kt:18 baz: param:int=6:int, b:int=2:int
|
||||
// test.kt:26 baz: param:int=6:int, b:int=2:int, $i$f$inlineCall:int=0:int
|
||||
// test.kt:27 baz: param:int=6:int, b:int=2:int, $i$f$inlineCall:int=0:int, e$iv:int=5:int
|
||||
// test.kt:19 baz: param:int=6:int, b:int=2:int, $i$f$inlineCall:int=0:int, e$iv:int=5:int, $i$a$-inlineCall-TestKt$bar$1$baz$1:int=0:int
|
||||
// EXPECTATIONS JVM_IR
|
||||
// test.kt:20 baz: param:int=6:int, b:int=2:int, $i$f$inlineCall:int=0:int, e$iv:int=5:int, $i$a$-inlineCall-TestKt$bar$1$baz$1:int=0:int, g:int=7:int
|
||||
// EXPECTATIONS JVM
|
||||
// test.kt:20 baz: param:int=6:int, b:int=2:int, $i$f$inlineCall:int=0:int, e$iv:int=5:int, $i$a$-inlineCall-TestKt$bar$1$baz$1:int=0:int
|
||||
// EXPECTATIONS JVM JVM_IR
|
||||
// test.kt:27 baz: param:int=6:int, b:int=2:int, $i$f$inlineCall:int=0:int, e$iv:int=5:int
|
||||
// test.kt:28 baz: param:int=6:int, b:int=2:int, $i$f$inlineCall:int=0:int, e$iv:int=5:int
|
||||
// test.kt:21 baz: param:int=6:int, b:int=2:int
|
||||
// test.kt:23 box: $i$f$bar:int=0:int
|
||||
// test.kt:38 box:
|
||||
|
||||
// EXPECTATIONS JS_IR
|
||||
// test.kt:10 box:
|
||||
// test.kt:3 <init>:
|
||||
// test.kt:10 box:
|
||||
// test.kt:5 baz: param=5:number
|
||||
// test.kt:26 baz: param=5:number, a=1:number
|
||||
// test.kt:7 baz: param=5:number, a=1:number, e=5:number
|
||||
// test.kt:9 baz: param=5:number, a=1:number, e=5:number, f=6:number
|
||||
// test.kt:22 box:
|
||||
// test.kt:14 <init>:
|
||||
// test.kt:22 box:
|
||||
// test.kt:16 baz: param=6:number
|
||||
// test.kt:36 baz: param=6:number, b=2:number
|
||||
// test.kt:26 baz: param=6:number, b=2:number, d=4:number
|
||||
// test.kt:19 baz: param=6:number, b=2:number, d=4:number, e=5:number
|
||||
// test.kt:21 baz: param=6:number, b=2:number, d=4:number, e=5:number, g=7:number
|
||||
// test.kt:38 box:
|
||||
@@ -0,0 +1,66 @@
|
||||
// FILE: test.kt
|
||||
inline fun foo(block: () -> Unit) {
|
||||
object {
|
||||
fun baz(param: Int) {
|
||||
val a = 1
|
||||
}
|
||||
}.baz(5)
|
||||
}
|
||||
|
||||
inline fun bar(crossinline block: () -> Unit) {
|
||||
object {
|
||||
fun baz(param: Int) {
|
||||
val b = 2
|
||||
block()
|
||||
}
|
||||
}.baz(6)
|
||||
}
|
||||
|
||||
fun box() {
|
||||
foo() {
|
||||
val c = 3
|
||||
}
|
||||
|
||||
bar() {
|
||||
val d = 4
|
||||
}
|
||||
}
|
||||
|
||||
// EXPECTATIONS JVM JVM_IR
|
||||
// test.kt:20 box:
|
||||
// test.kt:3 box: $i$f$foo:int=0:int
|
||||
// test.kt:3 <init>:
|
||||
// test.kt:7 box: $i$f$foo:int=0:int
|
||||
// test.kt:5 baz: param:int=5:int
|
||||
// test.kt:6 baz: param:int=5:int, a:int=1:int
|
||||
// test.kt:8 box: $i$f$foo:int=0:int
|
||||
// test.kt:24 box:
|
||||
// test.kt:11 box: $i$f$bar:int=0:int
|
||||
// test.kt:11 <init>:
|
||||
// test.kt:16 box: $i$f$bar:int=0:int
|
||||
// test.kt:13 baz: param:int=6:int
|
||||
// test.kt:14 baz: param:int=6:int, b:int=2:int
|
||||
// test.kt:25 baz: param:int=6:int, b:int=2:int, $i$a$-bar-TestKt$box$2:int=0:int
|
||||
// EXPECTATIONS JVM_IR
|
||||
// test.kt:26 baz: param:int=6:int, b:int=2:int, $i$a$-bar-TestKt$box$2:int=0:int, d:int=4:int
|
||||
// EXPECTATIONS JVM
|
||||
// test.kt:26 baz: param:int=6:int, b:int=2:int, $i$a$-bar-TestKt$box$2:int=0:int
|
||||
// EXPECTATIONS JVM JVM_IR
|
||||
// test.kt:14 baz: param:int=6:int, b:int=2:int
|
||||
// test.kt:15 baz: param:int=6:int, b:int=2:int
|
||||
// test.kt:17 box: $i$f$bar:int=0:int
|
||||
// test.kt:27 box:
|
||||
|
||||
// EXPECTATIONS JS_IR
|
||||
// test.kt:7 box:
|
||||
// test.kt:3 <init>:
|
||||
// test.kt:7 box:
|
||||
// test.kt:5 baz: param=5:number
|
||||
// test.kt:6 baz: param=5:number, a=1:number
|
||||
// test.kt:16 box:
|
||||
// test.kt:11 <init>:
|
||||
// test.kt:16 box:
|
||||
// test.kt:13 baz: param=6:number
|
||||
// test.kt:25 baz: param=6:number, b=2:number
|
||||
// test.kt:15 baz: param=6:number, b=2:number, d=4:number
|
||||
// test.kt:27 box:
|
||||
+12
@@ -67,6 +67,12 @@ public class IrLocalVariableBytecodeInlinerTestGenerated extends AbstractIrLocal
|
||||
runTest("compiler/testData/debug/localVariables/forLoopMultiline.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inlineFunInObject.kt")
|
||||
public void testInlineFunInObject() throws Exception {
|
||||
runTest("compiler/testData/debug/localVariables/inlineFunInObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inlineProperty.kt")
|
||||
public void testInlineProperty() throws Exception {
|
||||
@@ -79,6 +85,12 @@ public class IrLocalVariableBytecodeInlinerTestGenerated extends AbstractIrLocal
|
||||
runTest("compiler/testData/debug/localVariables/jvmOverloads.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaInObject.kt")
|
||||
public void testLambdaInObject() throws Exception {
|
||||
runTest("compiler/testData/debug/localVariables/lambdaInObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaWithLambdaParameter.kt")
|
||||
public void testLambdaWithLambdaParameter() throws Exception {
|
||||
|
||||
+12
@@ -67,6 +67,12 @@ public class IrLocalVariableIrInlinerTestGenerated extends AbstractIrLocalVariab
|
||||
runTest("compiler/testData/debug/localVariables/forLoopMultiline.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inlineFunInObject.kt")
|
||||
public void testInlineFunInObject() throws Exception {
|
||||
runTest("compiler/testData/debug/localVariables/inlineFunInObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inlineProperty.kt")
|
||||
public void testInlineProperty() throws Exception {
|
||||
@@ -79,6 +85,12 @@ public class IrLocalVariableIrInlinerTestGenerated extends AbstractIrLocalVariab
|
||||
runTest("compiler/testData/debug/localVariables/jvmOverloads.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaInObject.kt")
|
||||
public void testLambdaInObject() throws Exception {
|
||||
runTest("compiler/testData/debug/localVariables/lambdaInObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaWithLambdaParameter.kt")
|
||||
public void testLambdaWithLambdaParameter() throws Exception {
|
||||
|
||||
+12
@@ -67,6 +67,12 @@ public class LocalVariableTestGenerated extends AbstractLocalVariableTest {
|
||||
runTest("compiler/testData/debug/localVariables/forLoopMultiline.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inlineFunInObject.kt")
|
||||
public void testInlineFunInObject() throws Exception {
|
||||
runTest("compiler/testData/debug/localVariables/inlineFunInObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inlineProperty.kt")
|
||||
public void testInlineProperty() throws Exception {
|
||||
@@ -79,6 +85,12 @@ public class LocalVariableTestGenerated extends AbstractLocalVariableTest {
|
||||
runTest("compiler/testData/debug/localVariables/jvmOverloads.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaInObject.kt")
|
||||
public void testLambdaInObject() throws Exception {
|
||||
runTest("compiler/testData/debug/localVariables/lambdaInObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaWithLambdaParameter.kt")
|
||||
public void testLambdaWithLambdaParameter() throws Exception {
|
||||
|
||||
+12
@@ -67,6 +67,12 @@ public class IrJsLocalVariableTestGenerated extends AbstractIrJsLocalVariableTes
|
||||
runTest("compiler/testData/debug/localVariables/forLoopMultiline.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inlineFunInObject.kt")
|
||||
public void testInlineFunInObject() throws Exception {
|
||||
runTest("compiler/testData/debug/localVariables/inlineFunInObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inlineProperty.kt")
|
||||
public void testInlineProperty() throws Exception {
|
||||
@@ -79,6 +85,12 @@ public class IrJsLocalVariableTestGenerated extends AbstractIrJsLocalVariableTes
|
||||
runTest("compiler/testData/debug/localVariables/jsCode.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaInObject.kt")
|
||||
public void testLambdaInObject() throws Exception {
|
||||
runTest("compiler/testData/debug/localVariables/lambdaInObject.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaWithLambdaParameter.kt")
|
||||
public void testLambdaWithLambdaParameter() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user