Get accessors for companion object properties through wrapper class
This commit is contained in:
@@ -1663,7 +1663,8 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
|
||||
|
||||
// `this` is represented as first parameter of function in erased inline class
|
||||
if (contextKind() == OwnerKind.ERASED_INLINE_CLASS) {
|
||||
if (contextKind() == OwnerKind.ERASED_INLINE_CLASS &&
|
||||
InlineClassesUtilsKt.isInlineClass(propertyDescriptor.getContainingDeclaration())) {
|
||||
Type underlyingRepresentationType = typeMapper.mapType(propertyDescriptor.getType());
|
||||
return StackValue.local(0, underlyingRepresentationType);
|
||||
}
|
||||
|
||||
@@ -810,13 +810,13 @@ public class KotlinTypeMapper {
|
||||
}
|
||||
}
|
||||
else {
|
||||
boolean isInsideInlineClass = currentOwner.isInline();
|
||||
boolean toInlinedErasedClass = currentOwner.isInline() && !isAccessor(functionDescriptor);
|
||||
|
||||
boolean isStaticInvocation = (isStaticDeclaration(functionDescriptor) &&
|
||||
!(functionDescriptor instanceof ImportedFromObjectCallableDescriptor)) ||
|
||||
isStaticAccessor(functionDescriptor) ||
|
||||
CodegenUtilKt.isJvmStaticInObjectOrClassOrInterface(functionDescriptor) ||
|
||||
isInsideInlineClass;
|
||||
toInlinedErasedClass;
|
||||
if (isStaticInvocation) {
|
||||
invokeOpcode = INVOKESTATIC;
|
||||
isInterfaceMember = currentIsInterface && currentOwner instanceof JavaClassDescriptor;
|
||||
@@ -838,7 +838,7 @@ public class KotlinTypeMapper {
|
||||
? overriddenSpecialBuiltinFunction.getOriginal()
|
||||
: functionDescriptor.getOriginal();
|
||||
|
||||
signature = isInsideInlineClass
|
||||
signature = toInlinedErasedClass
|
||||
? mapSignatureForInlineErasedClassSkipGeneric(functionToCall)
|
||||
: mapSignatureSkipGeneric(functionToCall);
|
||||
returnKotlinType = functionToCall.getReturnType();
|
||||
@@ -846,7 +846,7 @@ public class KotlinTypeMapper {
|
||||
ClassDescriptor receiver = (currentIsInterface && !originalIsInterface) || currentOwner instanceof FunctionClassDescriptor
|
||||
? declarationOwner
|
||||
: currentOwner;
|
||||
owner = isInsideInlineClass ? mapErasedInlineClass(receiver) : mapClass(receiver);
|
||||
owner = toInlinedErasedClass ? mapErasedInlineClass(receiver) : mapClass(receiver);
|
||||
thisClass = owner;
|
||||
dispatchReceiverKotlinType = receiver.getDefaultType();
|
||||
}
|
||||
|
||||
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
inline class Foo(val c: Char) {
|
||||
companion object {
|
||||
val prop = "O"
|
||||
const val constVal = 1
|
||||
fun funInCompanion(): String = "K"
|
||||
}
|
||||
|
||||
fun simple() {
|
||||
prop
|
||||
constVal
|
||||
funInCompanion()
|
||||
}
|
||||
|
||||
fun asResult(): String = prop + constVal + funInCompanion() + c
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val r = Foo('2')
|
||||
if (r.asResult() != "O1K2") return "fail"
|
||||
return "OK"
|
||||
}
|
||||
Generated
+6
@@ -10341,6 +10341,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("referToPropertyInCompanionObjectOfInlineClass.kt")
|
||||
public void testReferToPropertyInCompanionObjectOfInlineClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/referToPropertyInCompanionObjectOfInlineClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("useInlineFunctionInsideInlineClass.kt")
|
||||
public void testUseInlineFunctionInsideInlineClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/useInlineFunctionInsideInlineClass.kt");
|
||||
|
||||
+6
@@ -10341,6 +10341,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("referToPropertyInCompanionObjectOfInlineClass.kt")
|
||||
public void testReferToPropertyInCompanionObjectOfInlineClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/referToPropertyInCompanionObjectOfInlineClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("useInlineFunctionInsideInlineClass.kt")
|
||||
public void testUseInlineFunctionInsideInlineClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/useInlineFunctionInsideInlineClass.kt");
|
||||
|
||||
+6
@@ -10341,6 +10341,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("referToPropertyInCompanionObjectOfInlineClass.kt")
|
||||
public void testReferToPropertyInCompanionObjectOfInlineClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/referToPropertyInCompanionObjectOfInlineClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("useInlineFunctionInsideInlineClass.kt")
|
||||
public void testUseInlineFunctionInsideInlineClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/useInlineFunctionInsideInlineClass.kt");
|
||||
|
||||
+6
@@ -11301,6 +11301,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("referToPropertyInCompanionObjectOfInlineClass.kt")
|
||||
public void testReferToPropertyInCompanionObjectOfInlineClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/referToPropertyInCompanionObjectOfInlineClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("useInlineFunctionInsideInlineClass.kt")
|
||||
public void testUseInlineFunctionInsideInlineClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/useInlineFunctionInsideInlineClass.kt");
|
||||
|
||||
Reference in New Issue
Block a user