FIR: consider all functions in scope when computing dispatch receiver parameter.

This commit is contained in:
Jinseong Jeon
2020-03-24 22:58:42 -07:00
committed by Mikhail Glukhikh
parent de0c9a5c73
commit acbe3126b1
6 changed files with 48 additions and 9 deletions
@@ -77,17 +77,14 @@ class Fir2IrConversionScope {
fun parent(): IrDeclarationParent? = parentStack.lastOrNull() fun parent(): IrDeclarationParent? = parentStack.lastOrNull()
fun lastDispatchReceiverParameter(): IrValueParameter? { fun lastDispatchReceiverParameter(): IrValueParameter? {
var dispatchReceiver = functionStack.lastOrNull()?.dispatchReceiverParameter // Use the dispatch receiver of the containing/enclosing functions (from the last to the first)
// Use the dispatch receiver of the containing function for (function in functionStack.asReversed()) {
dispatchReceiver?.let { return it } function.dispatchReceiverParameter?.let { return it }
}
// Use the dispatch receiver of the enclosing function if any
dispatchReceiver = functionStack.elementAtOrNull(functionStack.size - 2)?.dispatchReceiverParameter
dispatchReceiver?.let { return it }
// Use the dispatch receiver of the containing class // Use the dispatch receiver of the containing class
val lastClassSymbol = classStack.lastOrNull()?.symbol val lastClass = classStack.lastOrNull()
return lastClassSymbol?.owner?.thisReceiver return lastClass?.thisReceiver
} }
fun lastClass(): IrClass? = classStack.lastOrNull() fun lastClass(): IrClass? = classStack.lastOrNull()
@@ -18285,6 +18285,16 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/properties/classFieldInsideNested.kt"); runTest("compiler/testData/codegen/box/properties/classFieldInsideNested.kt");
} }
@TestMetadata("classFieldInsideNestedLambda.kt")
public void testClassFieldInsideNestedLambda() throws Exception {
runTest("compiler/testData/codegen/box/properties/classFieldInsideNestedLambda.kt");
}
@TestMetadata("classFieldInsideNestedNestedLambda.kt")
public void testClassFieldInsideNestedNestedLambda() throws Exception {
runTest("compiler/testData/codegen/box/properties/classFieldInsideNestedNestedLambda.kt");
}
@TestMetadata("classObjectProperties.kt") @TestMetadata("classObjectProperties.kt")
public void testClassObjectProperties() throws Exception { public void testClassObjectProperties() throws Exception {
runTest("compiler/testData/codegen/box/properties/classObjectProperties.kt"); runTest("compiler/testData/codegen/box/properties/classObjectProperties.kt");
@@ -0,0 +1,6 @@
class My {
val my: String = "O"
get() = { { field }() }() + "K"
}
fun box() = My().my
@@ -0,0 +1,6 @@
class My {
val my: String = "O"
get() = { { { field }() }() }() + "K"
}
fun box() = My().my
@@ -19806,6 +19806,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/properties/classFieldInsideNested.kt"); runTest("compiler/testData/codegen/box/properties/classFieldInsideNested.kt");
} }
@TestMetadata("classFieldInsideNestedLambda.kt")
public void testClassFieldInsideNestedLambda() throws Exception {
runTest("compiler/testData/codegen/box/properties/classFieldInsideNestedLambda.kt");
}
@TestMetadata("classFieldInsideNestedNestedLambda.kt")
public void testClassFieldInsideNestedNestedLambda() throws Exception {
runTest("compiler/testData/codegen/box/properties/classFieldInsideNestedNestedLambda.kt");
}
@TestMetadata("classObjectProperties.kt") @TestMetadata("classObjectProperties.kt")
public void testClassObjectProperties() throws Exception { public void testClassObjectProperties() throws Exception {
runTest("compiler/testData/codegen/box/properties/classObjectProperties.kt"); runTest("compiler/testData/codegen/box/properties/classObjectProperties.kt");
@@ -18285,6 +18285,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/properties/classFieldInsideNested.kt"); runTest("compiler/testData/codegen/box/properties/classFieldInsideNested.kt");
} }
@TestMetadata("classFieldInsideNestedLambda.kt")
public void testClassFieldInsideNestedLambda() throws Exception {
runTest("compiler/testData/codegen/box/properties/classFieldInsideNestedLambda.kt");
}
@TestMetadata("classFieldInsideNestedNestedLambda.kt")
public void testClassFieldInsideNestedNestedLambda() throws Exception {
runTest("compiler/testData/codegen/box/properties/classFieldInsideNestedNestedLambda.kt");
}
@TestMetadata("classObjectProperties.kt") @TestMetadata("classObjectProperties.kt")
public void testClassObjectProperties() throws Exception { public void testClassObjectProperties() throws Exception {
runTest("compiler/testData/codegen/box/properties/classObjectProperties.kt"); runTest("compiler/testData/codegen/box/properties/classObjectProperties.kt");