Proper implement 'classForImplicitThis'
This commit is contained in:
+8
-5
@@ -33,11 +33,14 @@ import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
|||||||
class InnerClassesLowering(val context: BackendContext) : ClassLoweringPass {
|
class InnerClassesLowering(val context: BackendContext) : ClassLoweringPass {
|
||||||
private val IrValueSymbol.classForImplicitThis: IrClass?
|
private val IrValueSymbol.classForImplicitThis: IrClass?
|
||||||
// TODO: is this the correct way to get the class?
|
// TODO: is this the correct way to get the class?
|
||||||
// -1 means value is either IMPLICIT or EXTENSION receiver
|
get() =
|
||||||
get() = if (this is IrValueParameterSymbol && owner.index == -1 && owner.name.isSpecial /* <this> */)
|
if (this is IrValueParameterSymbol && owner.index == -1 &&
|
||||||
owner.type.classOrNull?.owner
|
(owner == (owner.parent as? IrFunction)?.dispatchReceiverParameter ||
|
||||||
else
|
owner == (owner.parent as? IrClass)?.thisReceiver)
|
||||||
null
|
) {
|
||||||
|
owner.type.classOrNull?.owner
|
||||||
|
} else
|
||||||
|
null
|
||||||
|
|
||||||
override fun lower(irClass: IrClass) {
|
override fun lower(irClass: IrClass) {
|
||||||
if (!irClass.isInner) return
|
if (!irClass.isInner) return
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
class Outer(val value: String) {
|
||||||
|
|
||||||
|
inner class Inner {
|
||||||
|
fun Outer.foo() = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Outer.Inner.test() = Outer("OK").foo()
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return Outer("Fail").Inner().test()
|
||||||
|
}
|
||||||
Vendored
-1
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND: JVM_IR
|
|
||||||
open class Base(val callback: () -> String)
|
open class Base(val callback: () -> String)
|
||||||
|
|
||||||
class Outer {
|
class Outer {
|
||||||
|
|||||||
compiler/testData/codegen/box/closures/captureInSuperConstructorCall/outerCapturedInInlineLambda2.kt
Vendored
-1
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND: JVM_IR
|
|
||||||
open class Base(val callback: () -> String)
|
open class Base(val callback: () -> String)
|
||||||
|
|
||||||
class Outer {
|
class Outer {
|
||||||
|
|||||||
+5
@@ -3667,6 +3667,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/classes/inner"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/classes/inner"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("extensionWithOuter.kt")
|
||||||
|
public void testExtensionWithOuter() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/classes/inner/extensionWithOuter.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("instantiateInDerived.kt")
|
@TestMetadata("instantiateInDerived.kt")
|
||||||
public void testInstantiateInDerived() throws Exception {
|
public void testInstantiateInDerived() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/classes/inner/instantiateInDerived.kt");
|
runTest("compiler/testData/codegen/box/classes/inner/instantiateInDerived.kt");
|
||||||
|
|||||||
+5
@@ -3667,6 +3667,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/classes/inner"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/classes/inner"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("extensionWithOuter.kt")
|
||||||
|
public void testExtensionWithOuter() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/classes/inner/extensionWithOuter.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("instantiateInDerived.kt")
|
@TestMetadata("instantiateInDerived.kt")
|
||||||
public void testInstantiateInDerived() throws Exception {
|
public void testInstantiateInDerived() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/classes/inner/instantiateInDerived.kt");
|
runTest("compiler/testData/codegen/box/classes/inner/instantiateInDerived.kt");
|
||||||
|
|||||||
+5
@@ -3647,6 +3647,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/classes/inner"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/classes/inner"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("extensionWithOuter.kt")
|
||||||
|
public void testExtensionWithOuter() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/classes/inner/extensionWithOuter.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("instantiateInDerived.kt")
|
@TestMetadata("instantiateInDerived.kt")
|
||||||
public void testInstantiateInDerived() throws Exception {
|
public void testInstantiateInDerived() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/classes/inner/instantiateInDerived.kt");
|
runTest("compiler/testData/codegen/box/classes/inner/instantiateInDerived.kt");
|
||||||
|
|||||||
Generated
+5
@@ -3052,6 +3052,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/classes/inner"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS_IR, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/classes/inner"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS_IR, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("extensionWithOuter.kt")
|
||||||
|
public void testExtensionWithOuter() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/classes/inner/extensionWithOuter.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("instantiateInDerived.kt")
|
@TestMetadata("instantiateInDerived.kt")
|
||||||
public void testInstantiateInDerived() throws Exception {
|
public void testInstantiateInDerived() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/classes/inner/instantiateInDerived.kt");
|
runTest("compiler/testData/codegen/box/classes/inner/instantiateInDerived.kt");
|
||||||
|
|||||||
+5
@@ -3052,6 +3052,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/classes/inner"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/classes/inner"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("extensionWithOuter.kt")
|
||||||
|
public void testExtensionWithOuter() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/classes/inner/extensionWithOuter.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("instantiateInDerived.kt")
|
@TestMetadata("instantiateInDerived.kt")
|
||||||
public void testInstantiateInDerived() throws Exception {
|
public void testInstantiateInDerived() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/classes/inner/instantiateInDerived.kt");
|
runTest("compiler/testData/codegen/box/classes/inner/instantiateInDerived.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user