Fix companion method access from inline class
#KT-27025
This commit is contained in:
@@ -253,10 +253,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
if (!(myClass instanceof KtClass)) return;
|
||||
if (!descriptor.isInline()) return;
|
||||
|
||||
CodegenContext parentContext = context.getParentContext();
|
||||
assert parentContext != null : "Parent context of inline class declaration should not be null";
|
||||
|
||||
ClassContext erasedInlineClassContext = parentContext.intoWrapperForErasedInlineClass(descriptor, state);
|
||||
ClassContext erasedInlineClassContext = context.intoWrapperForErasedInlineClass(descriptor, state);
|
||||
new ErasedInlineClassBodyCodegen((KtClass) myClass, erasedInlineClassContext, v, state, this).generate();
|
||||
}
|
||||
|
||||
@@ -270,7 +267,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
if (inlinedValue == null) return;
|
||||
|
||||
Type valueType = typeMapper.mapType(inlinedValue.getType());
|
||||
SimpleFunctionDescriptor functionDescriptor = InlineClassDescriptorResolver.INSTANCE.createUnboxFunctionDescriptor(this.descriptor);
|
||||
SimpleFunctionDescriptor functionDescriptor = InlineClassDescriptorResolver.createUnboxFunctionDescriptor(this.descriptor);
|
||||
assert functionDescriptor != null : "FunctionDescriptor for unbox method should be not null during codegen";
|
||||
|
||||
functionCodegen.generateMethod(
|
||||
|
||||
@@ -393,12 +393,16 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
public CodegenContext findParentContextWithDescriptor(DeclarationDescriptor descriptor) {
|
||||
CodegenContext c = this;
|
||||
while (c != null) {
|
||||
if (c.getContextDescriptor() == descriptor) break;
|
||||
if (!c.shouldSkipThisContextInHierarchy() && c.getContextDescriptor() == descriptor) break;
|
||||
c = c.getParentContext();
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
private boolean shouldSkipThisContextInHierarchy() {
|
||||
return getContextKind() == OwnerKind.ERASED_INLINE_CLASS;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private PropertyDescriptor getPropertyAccessor(
|
||||
@NotNull PropertyDescriptor propertyDescriptor,
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
inline class R(private val r: Int) {
|
||||
fun test() = pf()
|
||||
|
||||
companion object {
|
||||
private fun pf() = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = R(0).test()
|
||||
+5
@@ -12120,6 +12120,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/membersAccess"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("toPrivateCompanionFun.kt")
|
||||
public void testToPrivateCompanionFun() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionFun.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("toPrivateCompanionVal.kt")
|
||||
public void testToPrivateCompanionVal() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionVal.kt");
|
||||
|
||||
+5
@@ -12120,6 +12120,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/membersAccess"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("toPrivateCompanionFun.kt")
|
||||
public void testToPrivateCompanionFun() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionFun.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("toPrivateCompanionVal.kt")
|
||||
public void testToPrivateCompanionVal() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionVal.kt");
|
||||
|
||||
+5
@@ -12125,6 +12125,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/membersAccess"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("toPrivateCompanionFun.kt")
|
||||
public void testToPrivateCompanionFun() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionFun.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("toPrivateCompanionVal.kt")
|
||||
public void testToPrivateCompanionVal() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionVal.kt");
|
||||
|
||||
+5
@@ -10660,6 +10660,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/membersAccess"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("toPrivateCompanionFun.kt")
|
||||
public void testToPrivateCompanionFun() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionFun.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("toPrivateCompanionVal.kt")
|
||||
public void testToPrivateCompanionVal() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionVal.kt");
|
||||
|
||||
+5
@@ -11705,6 +11705,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/membersAccess"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
|
||||
}
|
||||
|
||||
@TestMetadata("toPrivateCompanionFun.kt")
|
||||
public void testToPrivateCompanionFun() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionFun.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("toPrivateCompanionVal.kt")
|
||||
public void testToPrivateCompanionVal() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionVal.kt");
|
||||
|
||||
Reference in New Issue
Block a user