Codegen: fix callable reference to member imported from object
This commit is contained in:
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.load.java.JvmAbi
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.JetCallableReferenceExpression
|
import org.jetbrains.kotlin.psi.JetCallableReferenceExpression
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorFactory
|
import org.jetbrains.kotlin.resolve.DescriptorFactory
|
||||||
|
import org.jetbrains.kotlin.resolve.PropertyImportedFromObject
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny
|
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny
|
||||||
@@ -154,6 +155,10 @@ public class PropertyReferenceCodegen(
|
|||||||
val fakeCodegen = ExpressionCodegen(
|
val fakeCodegen = ExpressionCodegen(
|
||||||
this, FrameMap(), OBJECT_TYPE, context.intoFunction(fakeDescriptor), state, this@PropertyReferenceCodegen
|
this, FrameMap(), OBJECT_TYPE, context.intoFunction(fakeDescriptor), state, this@PropertyReferenceCodegen
|
||||||
)
|
)
|
||||||
|
if (target is PropertyImportedFromObject) {
|
||||||
|
val containingObject = target.containingObject
|
||||||
|
StackValue.singleton(containingObject, typeMapper).put(typeMapper.mapClass(containingObject), this)
|
||||||
|
}
|
||||||
|
|
||||||
val receiver =
|
val receiver =
|
||||||
if (receiverType != null) StackValue.coercion(StackValue.local(1, OBJECT_TYPE), typeMapper.mapType(receiverType))
|
if (receiverType != null) StackValue.coercion(StackValue.local(1, OBJECT_TYPE), typeMapper.mapType(receiverType))
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class FunctionImportedFromObject(val functionFromObject: FunctionDescriptor) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PropertyImportedFromObject(private val propertyFromObject: PropertyDescriptor) :
|
class PropertyImportedFromObject(val propertyFromObject: PropertyDescriptor) :
|
||||||
PropertyDescriptor by propertyFromObject,
|
PropertyDescriptor by propertyFromObject,
|
||||||
ImportedFromObjectCallableDescriptor(propertyFromObject.containingDeclaration as ClassDescriptor) {
|
ImportedFromObjectCallableDescriptor(propertyFromObject.containingDeclaration as ClassDescriptor) {
|
||||||
override fun getDispatchReceiverParameter(): ReceiverParameterDescriptor? = null
|
override fun getDispatchReceiverParameter(): ReceiverParameterDescriptor? = null
|
||||||
|
|||||||
Vendored
+17
@@ -0,0 +1,17 @@
|
|||||||
|
import A.foo
|
||||||
|
import A.bar
|
||||||
|
|
||||||
|
object A {
|
||||||
|
fun foo() = "O"
|
||||||
|
fun String.foo() = "K"
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun bar(s: Int) = "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val static = (::bar)(0)
|
||||||
|
if (static != "OK") return "1"
|
||||||
|
|
||||||
|
return (::foo)() + (String::foo)("")
|
||||||
|
}
|
||||||
Vendored
+33
@@ -0,0 +1,33 @@
|
|||||||
|
import A.foo
|
||||||
|
import A.bar
|
||||||
|
import A.baz
|
||||||
|
|
||||||
|
object A {
|
||||||
|
var foo = "NotOk"
|
||||||
|
var String.foo: String
|
||||||
|
get() = "K"
|
||||||
|
set(i) {}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
val bar: String = "OK"
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
val String.baz: String
|
||||||
|
get() = "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
|
||||||
|
val static = (::bar).get()
|
||||||
|
if (static != "OK") return static
|
||||||
|
|
||||||
|
val staticExt = (String::baz).get("a")
|
||||||
|
if (staticExt != "OK") return staticExt
|
||||||
|
|
||||||
|
val nonExt = ::foo
|
||||||
|
|
||||||
|
nonExt.set("O")
|
||||||
|
val ext = String::foo
|
||||||
|
ext.set("", "Whatever")
|
||||||
|
return nonExt.get() + ext.get("")
|
||||||
|
}
|
||||||
+12
@@ -558,6 +558,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
|||||||
doTestWithStdlib(fileName);
|
doTestWithStdlib(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("memberImportedFromObject.kt")
|
||||||
|
public void testMemberImportedFromObject() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/function/memberImportedFromObject.kt");
|
||||||
|
doTestWithStdlib(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("nestedConstructorFromClass.kt")
|
@TestMetadata("nestedConstructorFromClass.kt")
|
||||||
public void testNestedConstructorFromClass() throws Exception {
|
public void testNestedConstructorFromClass() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/function/nestedConstructorFromClass.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/function/nestedConstructorFromClass.kt");
|
||||||
@@ -852,6 +858,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
|||||||
doTestWithStdlib(fileName);
|
doTestWithStdlib(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("memberImportedFromObject.kt")
|
||||||
|
public void testMemberImportedFromObject() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/property/memberImportedFromObject.kt");
|
||||||
|
doTestWithStdlib(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("overriddenInSubclass.kt")
|
@TestMetadata("overriddenInSubclass.kt")
|
||||||
public void testOverriddenInSubclass() throws Exception {
|
public void testOverriddenInSubclass() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/property/overriddenInSubclass.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/callableReference/property/overriddenInSubclass.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user