diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/codegen/ir/FirBlackBoxInlineCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/codegen/ir/FirBlackBoxInlineCodegenTestGenerated.java index 308a59f154c..3ed7216e2d4 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/codegen/ir/FirBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/codegen/ir/FirBlackBoxInlineCodegenTestGenerated.java @@ -246,6 +246,16 @@ public class FirBlackBoxInlineCodegenTestGenerated extends AbstractFirBlackBoxIn runTest("compiler/testData/codegen/boxInline/anonymousObject/kt38197.kt"); } + @TestMetadata("kt42815.kt") + public void testKt42815() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt42815.kt"); + } + + @TestMetadata("kt42815_delegated.kt") + public void testKt42815_delegated() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt42815_delegated.kt"); + } + @TestMetadata("kt6552.kt") public void testKt6552() throws Exception { runTest("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt"); diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrInlineReferenceLocator.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrInlineReferenceLocator.kt index ae1fed26604..246d685b5c6 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrInlineReferenceLocator.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrInlineReferenceLocator.kt @@ -9,10 +9,7 @@ import org.jetbrains.kotlin.backend.jvm.JvmBackendContext import org.jetbrains.kotlin.backend.jvm.codegen.isInlineFunctionCall import org.jetbrains.kotlin.backend.jvm.codegen.isInlineIrExpression import org.jetbrains.kotlin.ir.IrElement -import org.jetbrains.kotlin.ir.declarations.IrDeclaration -import org.jetbrains.kotlin.ir.declarations.IrDeclarationBase -import org.jetbrains.kotlin.ir.declarations.IrFunction -import org.jetbrains.kotlin.ir.declarations.IrValueParameter +import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.IrBlock import org.jetbrains.kotlin.ir.expressions.IrCallableReference import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression @@ -25,7 +22,8 @@ internal open class IrInlineReferenceLocator(private val context: JvmBackendCont } override fun visitDeclaration(declaration: IrDeclarationBase, data: IrDeclaration?) { - declaration.acceptChildren(this, declaration) + val scope = if (declaration is IrVariable) data else declaration + declaration.acceptChildren(this, scope) } override fun visitFunctionAccess(expression: IrFunctionAccessExpression, data: IrDeclaration?) { diff --git a/compiler/testData/codegen/boxInline/anonymousObject/kt42815.kt b/compiler/testData/codegen/boxInline/anonymousObject/kt42815.kt new file mode 100644 index 00000000000..9590ce4726f --- /dev/null +++ b/compiler/testData/codegen/boxInline/anonymousObject/kt42815.kt @@ -0,0 +1,21 @@ +// FILE: 1.kt +package test + +inline fun myRun(x: () -> String) = x() + +// FILE: 2.kt +// NO_CHECK_LAMBDA_INLINING +import test.* + +class C { + val x: String + init { + val y = myRun { { "OK" }() } + x = y + } + + constructor(y: Int) + constructor(y: String) +} + +fun box(): String = C("").x \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/anonymousObject/kt42815_delegated.kt b/compiler/testData/codegen/boxInline/anonymousObject/kt42815_delegated.kt new file mode 100644 index 00000000000..15051795575 --- /dev/null +++ b/compiler/testData/codegen/boxInline/anonymousObject/kt42815_delegated.kt @@ -0,0 +1,30 @@ +// WITH_RUNTIME +// FILE: 1.kt +package test + +inline fun myRun( x: () -> String): Lazy { + val value2 = x() + return object : Lazy { + override val value: String + get() = value2 + + override fun isInitialized(): Boolean = true + } +} + +// FILE: 2.kt + +import test.* + +class C { + val x: String + init { + val y by myRun { { "OK" }() } + x = y + } + + constructor(y: Int) + constructor(y: String) +} + +fun box(): String = C("").x \ No newline at end of file diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index ab94c7a571a..34f6d2cebd4 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -246,6 +246,16 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo runTest("compiler/testData/codegen/boxInline/anonymousObject/kt38197.kt"); } + @TestMetadata("kt42815.kt") + public void testKt42815() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt42815.kt"); + } + + @TestMetadata("kt42815_delegated.kt") + public void testKt42815_delegated() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt42815_delegated.kt"); + } + @TestMetadata("kt6552.kt") public void testKt6552() throws Exception { runTest("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index 2155efe0562..e3d11df63c5 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -246,6 +246,16 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi runTest("compiler/testData/codegen/boxInline/anonymousObject/kt38197.kt"); } + @TestMetadata("kt42815.kt") + public void testKt42815() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt42815.kt"); + } + + @TestMetadata("kt42815_delegated.kt") + public void testKt42815_delegated() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt42815_delegated.kt"); + } + @TestMetadata("kt6552.kt") public void testKt6552() throws Exception { runTest("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java index 5a6a62de7d2..339372300a6 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java @@ -246,6 +246,16 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli runTest("compiler/testData/codegen/boxInline/anonymousObject/kt38197.kt"); } + @TestMetadata("kt42815.kt") + public void testKt42815() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt42815.kt"); + } + + @TestMetadata("kt42815_delegated.kt") + public void testKt42815_delegated() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt42815_delegated.kt"); + } + @TestMetadata("kt6552.kt") public void testKt6552() throws Exception { runTest("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java index bc93b2fa427..bff2ed9cbd6 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java @@ -246,6 +246,16 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC runTest("compiler/testData/codegen/boxInline/anonymousObject/kt38197.kt"); } + @TestMetadata("kt42815.kt") + public void testKt42815() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt42815.kt"); + } + + @TestMetadata("kt42815_delegated.kt") + public void testKt42815_delegated() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt42815_delegated.kt"); + } + @TestMetadata("kt6552.kt") public void testKt6552() throws Exception { runTest("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmIrAgainstOldBoxInlineTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmIrAgainstOldBoxInlineTestGenerated.java index e607d85e13a..667670a5fff 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmIrAgainstOldBoxInlineTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmIrAgainstOldBoxInlineTestGenerated.java @@ -246,6 +246,16 @@ public class JvmIrAgainstOldBoxInlineTestGenerated extends AbstractJvmIrAgainstO runTest("compiler/testData/codegen/boxInline/anonymousObject/kt38197.kt"); } + @TestMetadata("kt42815.kt") + public void testKt42815() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt42815.kt"); + } + + @TestMetadata("kt42815_delegated.kt") + public void testKt42815_delegated() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt42815_delegated.kt"); + } + @TestMetadata("kt6552.kt") public void testKt6552() throws Exception { runTest("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmOldAgainstIrBoxInlineTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmOldAgainstIrBoxInlineTestGenerated.java index 6d9b781d163..36a35e81b21 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmOldAgainstIrBoxInlineTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/ir/JvmOldAgainstIrBoxInlineTestGenerated.java @@ -246,6 +246,16 @@ public class JvmOldAgainstIrBoxInlineTestGenerated extends AbstractJvmOldAgainst runTest("compiler/testData/codegen/boxInline/anonymousObject/kt38197.kt"); } + @TestMetadata("kt42815.kt") + public void testKt42815() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt42815.kt"); + } + + @TestMetadata("kt42815_delegated.kt") + public void testKt42815_delegated() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt42815_delegated.kt"); + } + @TestMetadata("kt6552.kt") public void testKt6552() throws Exception { runTest("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenInlineES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenInlineES6TestGenerated.java index 7b09e3c6123..b758b1ee66b 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenInlineES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenInlineES6TestGenerated.java @@ -226,6 +226,16 @@ public class IrJsCodegenInlineES6TestGenerated extends AbstractIrJsCodegenInline runTest("compiler/testData/codegen/boxInline/anonymousObject/kt38197.kt"); } + @TestMetadata("kt42815.kt") + public void testKt42815() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt42815.kt"); + } + + @TestMetadata("kt42815_delegated.kt") + public void testKt42815_delegated() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt42815_delegated.kt"); + } + @TestMetadata("kt6552.kt") public void testKt6552() throws Exception { runTest("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenInlineTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenInlineTestGenerated.java index 7960803a286..23d718edc84 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenInlineTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenInlineTestGenerated.java @@ -226,6 +226,16 @@ public class IrJsCodegenInlineTestGenerated extends AbstractIrJsCodegenInlineTes runTest("compiler/testData/codegen/boxInline/anonymousObject/kt38197.kt"); } + @TestMetadata("kt42815.kt") + public void testKt42815() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt42815.kt"); + } + + @TestMetadata("kt42815_delegated.kt") + public void testKt42815_delegated() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt42815_delegated.kt"); + } + @TestMetadata("kt6552.kt") public void testKt6552() throws Exception { runTest("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenInlineTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenInlineTestGenerated.java index 9d1de7d54f0..9a4df584fd9 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenInlineTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenInlineTestGenerated.java @@ -226,6 +226,16 @@ public class JsCodegenInlineTestGenerated extends AbstractJsCodegenInlineTest { runTest("compiler/testData/codegen/boxInline/anonymousObject/kt38197.kt"); } + @TestMetadata("kt42815.kt") + public void testKt42815() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt42815.kt"); + } + + @TestMetadata("kt42815_delegated.kt") + public void testKt42815_delegated() throws Exception { + runTest("compiler/testData/codegen/boxInline/anonymousObject/kt42815_delegated.kt"); + } + @TestMetadata("kt6552.kt") public void testKt6552() throws Exception { runTest("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt");