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 (!(myClass instanceof KtClass)) return;
|
||||||
if (!descriptor.isInline()) return;
|
if (!descriptor.isInline()) return;
|
||||||
|
|
||||||
CodegenContext parentContext = context.getParentContext();
|
ClassContext erasedInlineClassContext = context.intoWrapperForErasedInlineClass(descriptor, state);
|
||||||
assert parentContext != null : "Parent context of inline class declaration should not be null";
|
|
||||||
|
|
||||||
ClassContext erasedInlineClassContext = parentContext.intoWrapperForErasedInlineClass(descriptor, state);
|
|
||||||
new ErasedInlineClassBodyCodegen((KtClass) myClass, erasedInlineClassContext, v, state, this).generate();
|
new ErasedInlineClassBodyCodegen((KtClass) myClass, erasedInlineClassContext, v, state, this).generate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,7 +267,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
if (inlinedValue == null) return;
|
if (inlinedValue == null) return;
|
||||||
|
|
||||||
Type valueType = typeMapper.mapType(inlinedValue.getType());
|
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";
|
assert functionDescriptor != null : "FunctionDescriptor for unbox method should be not null during codegen";
|
||||||
|
|
||||||
functionCodegen.generateMethod(
|
functionCodegen.generateMethod(
|
||||||
|
|||||||
@@ -393,12 +393,16 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
|||||||
public CodegenContext findParentContextWithDescriptor(DeclarationDescriptor descriptor) {
|
public CodegenContext findParentContextWithDescriptor(DeclarationDescriptor descriptor) {
|
||||||
CodegenContext c = this;
|
CodegenContext c = this;
|
||||||
while (c != null) {
|
while (c != null) {
|
||||||
if (c.getContextDescriptor() == descriptor) break;
|
if (!c.shouldSkipThisContextInHierarchy() && c.getContextDescriptor() == descriptor) break;
|
||||||
c = c.getParentContext();
|
c = c.getParentContext();
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean shouldSkipThisContextInHierarchy() {
|
||||||
|
return getContextKind() == OwnerKind.ERASED_INLINE_CLASS;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private PropertyDescriptor getPropertyAccessor(
|
private PropertyDescriptor getPropertyAccessor(
|
||||||
@NotNull PropertyDescriptor propertyDescriptor,
|
@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);
|
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")
|
@TestMetadata("toPrivateCompanionVal.kt")
|
||||||
public void testToPrivateCompanionVal() throws Exception {
|
public void testToPrivateCompanionVal() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionVal.kt");
|
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);
|
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")
|
@TestMetadata("toPrivateCompanionVal.kt")
|
||||||
public void testToPrivateCompanionVal() throws Exception {
|
public void testToPrivateCompanionVal() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionVal.kt");
|
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);
|
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")
|
@TestMetadata("toPrivateCompanionVal.kt")
|
||||||
public void testToPrivateCompanionVal() throws Exception {
|
public void testToPrivateCompanionVal() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionVal.kt");
|
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);
|
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")
|
@TestMetadata("toPrivateCompanionVal.kt")
|
||||||
public void testToPrivateCompanionVal() throws Exception {
|
public void testToPrivateCompanionVal() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionVal.kt");
|
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);
|
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")
|
@TestMetadata("toPrivateCompanionVal.kt")
|
||||||
public void testToPrivateCompanionVal() throws Exception {
|
public void testToPrivateCompanionVal() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionVal.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/membersAccess/toPrivateCompanionVal.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user