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;
|
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
|
||||||
|
|
||||||
// `this` is represented as first parameter of function in erased inline class
|
// `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());
|
Type underlyingRepresentationType = typeMapper.mapType(propertyDescriptor.getType());
|
||||||
return StackValue.local(0, underlyingRepresentationType);
|
return StackValue.local(0, underlyingRepresentationType);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -810,13 +810,13 @@ public class KotlinTypeMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
boolean isInsideInlineClass = currentOwner.isInline();
|
boolean toInlinedErasedClass = currentOwner.isInline() && !isAccessor(functionDescriptor);
|
||||||
|
|
||||||
boolean isStaticInvocation = (isStaticDeclaration(functionDescriptor) &&
|
boolean isStaticInvocation = (isStaticDeclaration(functionDescriptor) &&
|
||||||
!(functionDescriptor instanceof ImportedFromObjectCallableDescriptor)) ||
|
!(functionDescriptor instanceof ImportedFromObjectCallableDescriptor)) ||
|
||||||
isStaticAccessor(functionDescriptor) ||
|
isStaticAccessor(functionDescriptor) ||
|
||||||
CodegenUtilKt.isJvmStaticInObjectOrClassOrInterface(functionDescriptor) ||
|
CodegenUtilKt.isJvmStaticInObjectOrClassOrInterface(functionDescriptor) ||
|
||||||
isInsideInlineClass;
|
toInlinedErasedClass;
|
||||||
if (isStaticInvocation) {
|
if (isStaticInvocation) {
|
||||||
invokeOpcode = INVOKESTATIC;
|
invokeOpcode = INVOKESTATIC;
|
||||||
isInterfaceMember = currentIsInterface && currentOwner instanceof JavaClassDescriptor;
|
isInterfaceMember = currentIsInterface && currentOwner instanceof JavaClassDescriptor;
|
||||||
@@ -838,7 +838,7 @@ public class KotlinTypeMapper {
|
|||||||
? overriddenSpecialBuiltinFunction.getOriginal()
|
? overriddenSpecialBuiltinFunction.getOriginal()
|
||||||
: functionDescriptor.getOriginal();
|
: functionDescriptor.getOriginal();
|
||||||
|
|
||||||
signature = isInsideInlineClass
|
signature = toInlinedErasedClass
|
||||||
? mapSignatureForInlineErasedClassSkipGeneric(functionToCall)
|
? mapSignatureForInlineErasedClassSkipGeneric(functionToCall)
|
||||||
: mapSignatureSkipGeneric(functionToCall);
|
: mapSignatureSkipGeneric(functionToCall);
|
||||||
returnKotlinType = functionToCall.getReturnType();
|
returnKotlinType = functionToCall.getReturnType();
|
||||||
@@ -846,7 +846,7 @@ public class KotlinTypeMapper {
|
|||||||
ClassDescriptor receiver = (currentIsInterface && !originalIsInterface) || currentOwner instanceof FunctionClassDescriptor
|
ClassDescriptor receiver = (currentIsInterface && !originalIsInterface) || currentOwner instanceof FunctionClassDescriptor
|
||||||
? declarationOwner
|
? declarationOwner
|
||||||
: currentOwner;
|
: currentOwner;
|
||||||
owner = isInsideInlineClass ? mapErasedInlineClass(receiver) : mapClass(receiver);
|
owner = toInlinedErasedClass ? mapErasedInlineClass(receiver) : mapClass(receiver);
|
||||||
thisClass = owner;
|
thisClass = owner;
|
||||||
dispatchReceiverKotlinType = receiver.getDefaultType();
|
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);
|
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")
|
@TestMetadata("useInlineFunctionInsideInlineClass.kt")
|
||||||
public void testUseInlineFunctionInsideInlineClass() throws Exception {
|
public void testUseInlineFunctionInsideInlineClass() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/useInlineFunctionInsideInlineClass.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/useInlineFunctionInsideInlineClass.kt");
|
||||||
|
|||||||
+6
@@ -10341,6 +10341,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("useInlineFunctionInsideInlineClass.kt")
|
||||||
public void testUseInlineFunctionInsideInlineClass() throws Exception {
|
public void testUseInlineFunctionInsideInlineClass() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/useInlineFunctionInsideInlineClass.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/useInlineFunctionInsideInlineClass.kt");
|
||||||
|
|||||||
+6
@@ -10341,6 +10341,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("useInlineFunctionInsideInlineClass.kt")
|
||||||
public void testUseInlineFunctionInsideInlineClass() throws Exception {
|
public void testUseInlineFunctionInsideInlineClass() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/useInlineFunctionInsideInlineClass.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/useInlineFunctionInsideInlineClass.kt");
|
||||||
|
|||||||
+6
@@ -11301,6 +11301,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("useInlineFunctionInsideInlineClass.kt")
|
||||||
public void testUseInlineFunctionInsideInlineClass() throws Exception {
|
public void testUseInlineFunctionInsideInlineClass() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/useInlineFunctionInsideInlineClass.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/useInlineFunctionInsideInlineClass.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user