Use original descriptors to create symbols for callable references
This commit is contained in:
+2
-2
@@ -37,7 +37,7 @@ class LocalFunctionGenerator(statementGenerator: StatementGenerator) : Statement
|
||||
irBlock.statements.add(
|
||||
IrFunctionReferenceImpl(
|
||||
ktLambda.startOffset, ktLambda.endOffset, lambdaExpressionType,
|
||||
irLambdaFunction.symbol,
|
||||
irLambdaFunction.symbol, irLambdaFunction.symbol.descriptor,
|
||||
null, IrStatementOrigin.LAMBDA
|
||||
)
|
||||
)
|
||||
@@ -59,7 +59,7 @@ class LocalFunctionGenerator(statementGenerator: StatementGenerator) : Statement
|
||||
irBlock.statements.add(
|
||||
IrFunctionReferenceImpl(
|
||||
ktFun.startOffset, ktFun.endOffset, funExpressionType,
|
||||
irFun.symbol,
|
||||
irFun.symbol, irFun.symbol.descriptor,
|
||||
null, IrStatementOrigin.ANONYMOUS_FUNCTION
|
||||
)
|
||||
)
|
||||
|
||||
+7
-5
@@ -42,7 +42,7 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St
|
||||
}
|
||||
else {
|
||||
val typeConstructorDeclaration = lhs.type.constructor.declarationDescriptor
|
||||
val typeClass = typeConstructorDeclaration as? ClassifierDescriptor ?:
|
||||
val typeClass = typeConstructorDeclaration ?:
|
||||
throw AssertionError("Unexpected type constructor for ${lhs.type}: $typeConstructorDeclaration")
|
||||
IrClassReferenceImpl(ktClassLiteral.startOffset, ktClassLiteral.endOffset, resultType,
|
||||
context.symbolTable.referenceClassifier(typeClass))
|
||||
@@ -83,7 +83,8 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St
|
||||
is FunctionDescriptor ->
|
||||
generateFunctionReference(
|
||||
startOffset, endOffset, type,
|
||||
context.symbolTable.referenceFunction(callableDescriptor),
|
||||
context.symbolTable.referenceFunction(callableDescriptor.original),
|
||||
callableDescriptor,
|
||||
typeArguments,
|
||||
origin
|
||||
)
|
||||
@@ -128,8 +129,8 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St
|
||||
val setterDescriptor = propertyDescriptor.setter
|
||||
|
||||
val fieldSymbol = if (getterDescriptor == null) context.symbolTable.referenceField(propertyDescriptor) else null
|
||||
val getterSymbol = getterDescriptor?.let { context.symbolTable.referenceFunction(it) }
|
||||
val setterSymbol = setterDescriptor?.let { context.symbolTable.referenceFunction(it) }
|
||||
val getterSymbol = getterDescriptor?.let { context.symbolTable.referenceFunction(it.original) }
|
||||
val setterSymbol = setterDescriptor?.let { context.symbolTable.referenceFunction(it.original) }
|
||||
|
||||
return IrPropertyReferenceImpl(
|
||||
startOffset, endOffset, type,
|
||||
@@ -145,12 +146,13 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St
|
||||
endOffset: Int,
|
||||
type: KotlinType,
|
||||
symbol: IrFunctionSymbol,
|
||||
descriptor: FunctionDescriptor,
|
||||
typeArguments: Map<TypeParameterDescriptor, KotlinType>?,
|
||||
origin: IrStatementOrigin?
|
||||
): IrFunctionReference =
|
||||
IrFunctionReferenceImpl(
|
||||
startOffset, endOffset, type,
|
||||
symbol,
|
||||
symbol, descriptor,
|
||||
typeArguments,
|
||||
origin
|
||||
)
|
||||
|
||||
+2
-3
@@ -30,6 +30,7 @@ class IrFunctionReferenceImpl(
|
||||
endOffset: Int,
|
||||
type: KotlinType,
|
||||
override val symbol: IrFunctionSymbol,
|
||||
override val descriptor: FunctionDescriptor,
|
||||
typeArguments: Map<TypeParameterDescriptor, KotlinType>?,
|
||||
origin: IrStatementOrigin? = null
|
||||
) : IrFunctionReference,
|
||||
@@ -48,9 +49,7 @@ class IrFunctionReferenceImpl(
|
||||
descriptor: FunctionDescriptor,
|
||||
typeArguments: Map<TypeParameterDescriptor, KotlinType>?,
|
||||
origin: IrStatementOrigin? = null
|
||||
) : this(startOffset, endOffset, type, createFunctionSymbol(descriptor), typeArguments, origin)
|
||||
|
||||
override val descriptor: FunctionDescriptor get() = symbol.descriptor
|
||||
) : this(startOffset, endOffset, type, createFunctionSymbol(descriptor.original), descriptor, typeArguments, origin)
|
||||
|
||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||
visitor.visitFunctionReference(this, data)
|
||||
|
||||
@@ -409,7 +409,7 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
||||
return IrFunctionReferenceImpl(
|
||||
expression.startOffset, expression.endOffset,
|
||||
expression.type,
|
||||
newCallee,
|
||||
newCallee.original,
|
||||
expression.transformTypeArguments(newCallee),
|
||||
mapStatementOrigin(expression.origin)
|
||||
).transformValueArguments(expression)
|
||||
@@ -418,8 +418,8 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
||||
override fun visitPropertyReference(expression: IrPropertyReference): IrExpression {
|
||||
val newProperty = mapPropertyReference(expression.descriptor)
|
||||
val newFieldSymbol = if (newProperty.getter == null) IrFieldSymbolImpl(newProperty) else null
|
||||
val newGetterSymbol = newProperty.getter?.let { IrSimpleFunctionSymbolImpl(it) }
|
||||
val newSetterSymbol = newProperty.setter?.let { IrSimpleFunctionSymbolImpl(it) }
|
||||
val newGetterSymbol = newProperty.getter?.let { IrSimpleFunctionSymbolImpl(it.original) }
|
||||
val newSetterSymbol = newProperty.setter?.let { IrSimpleFunctionSymbolImpl(it.original) }
|
||||
return IrPropertyReferenceImpl(
|
||||
expression.startOffset, expression.endOffset, expression.type,
|
||||
newProperty, newFieldSymbol, newGetterSymbol, newSetterSymbol,
|
||||
@@ -432,8 +432,8 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
||||
val newLocalDelegatedProperty = mapLocalPropertyReference(expression.descriptor)
|
||||
val newDelegateDescriptor = mapVariableReference(expression.delegate.descriptor)
|
||||
val newDelegateSymbol = IrVariableSymbolImpl(newDelegateDescriptor)
|
||||
val newGetterSymbol = newLocalDelegatedProperty.getter!!.let { IrSimpleFunctionSymbolImpl(it) }
|
||||
val newSetterSymbol = newLocalDelegatedProperty.setter?.let { IrSimpleFunctionSymbolImpl(it) }
|
||||
val newGetterSymbol = newLocalDelegatedProperty.getter!!.let { IrSimpleFunctionSymbolImpl(it.original) }
|
||||
val newSetterSymbol = newLocalDelegatedProperty.setter?.let { IrSimpleFunctionSymbolImpl(it.original) }
|
||||
return IrLocalDelegatedPropertyReferenceImpl(
|
||||
expression.startOffset, expression.endOffset, expression.type,
|
||||
newLocalDelegatedProperty,
|
||||
|
||||
@@ -378,6 +378,7 @@ class DeepCopyIrTreeWithSymbols(private val symbolsRemapper: DeepCopySymbolsRema
|
||||
expression.startOffset, expression.endOffset,
|
||||
expression.type,
|
||||
symbolsRemapper.getReferencedFunction(expression.symbol),
|
||||
expression.descriptor, // TODO substitute referenced descriptor
|
||||
expression.getTypeArgumentsMap(),
|
||||
mapStatementOrigin(expression.origin)
|
||||
).transformValueArguments(expression)
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class A<T> {
|
||||
fun foo() {}
|
||||
val bar = 42
|
||||
}
|
||||
|
||||
val test1 = A<String>::foo
|
||||
val test2 = A<String>::bar
|
||||
@@ -0,0 +1,44 @@
|
||||
FILE /callableRefToGenericMember.kt
|
||||
CLASS CLASS A
|
||||
$this: VALUE_PARAMETER this@A: A<T>
|
||||
TYPE_PARAMETER <T>
|
||||
CONSTRUCTOR public constructor A<T>()
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'constructor Any()'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='A'
|
||||
FUN public final fun foo(): kotlin.Unit
|
||||
$this: VALUE_PARAMETER this@A: A<T>
|
||||
BLOCK_BODY
|
||||
PROPERTY public final val bar: kotlin.Int = 42
|
||||
FIELD PROPERTY_BACKING_FIELD public final val bar: kotlin.Int = 42
|
||||
EXPRESSION_BODY
|
||||
CONST Int type=kotlin.Int value='42'
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR public final fun <get-bar>(): kotlin.Int
|
||||
$this: VALUE_PARAMETER this@A: A<T>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='<get-bar>(): Int'
|
||||
GET_FIELD 'bar: Int' type=kotlin.Int origin=null
|
||||
receiver: GET_VAR 'this@A: A<T>' type=A<T> origin=null
|
||||
FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean
|
||||
$this: VALUE_PARAMETER this@Any: Any
|
||||
VALUE_PARAMETER value-parameter other: kotlin.Any?
|
||||
FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int
|
||||
$this: VALUE_PARAMETER this@Any: Any
|
||||
FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String
|
||||
$this: VALUE_PARAMETER this@Any: Any
|
||||
PROPERTY public val test1: kotlin.reflect.KFunction1<A<kotlin.String>, kotlin.Unit>
|
||||
FIELD PROPERTY_BACKING_FIELD public val test1: kotlin.reflect.KFunction1<A<kotlin.String>, kotlin.Unit>
|
||||
EXPRESSION_BODY
|
||||
FUNCTION_REFERENCE 'foo(): Unit' type=kotlin.reflect.KFunction1<A<kotlin.String>, kotlin.Unit> origin=null
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR public fun <get-test1>(): kotlin.reflect.KFunction1<A<kotlin.String>, kotlin.Unit>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='<get-test1>(): KFunction1<A<String>, Unit>'
|
||||
GET_FIELD 'test1: KFunction1<A<String>, Unit>' type=kotlin.reflect.KFunction1<A<kotlin.String>, kotlin.Unit> origin=null
|
||||
PROPERTY public val test2: kotlin.reflect.KProperty1<A<kotlin.String>, kotlin.Int>
|
||||
FIELD PROPERTY_BACKING_FIELD public val test2: kotlin.reflect.KProperty1<A<kotlin.String>, kotlin.Int>
|
||||
EXPRESSION_BODY
|
||||
PROPERTY_REFERENCE 'bar: Int' field=null getter='<get-bar>(): Int' setter=null type=kotlin.reflect.KProperty1<A<kotlin.String>, kotlin.Int> origin=null
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR public fun <get-test2>(): kotlin.reflect.KProperty1<A<kotlin.String>, kotlin.Int>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='<get-test2>(): KProperty1<A<String>, Int>'
|
||||
GET_FIELD 'test2: KProperty1<A<String>, Int>' type=kotlin.reflect.KProperty1<A<kotlin.String>, kotlin.Int> origin=null
|
||||
@@ -545,6 +545,12 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("callableRefToGenericMember.kt")
|
||||
public void testCallableRefToGenericMember() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/expressions/callableRefToGenericMember.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("calls.kt")
|
||||
public void testCalls() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/expressions/calls.kt");
|
||||
|
||||
Reference in New Issue
Block a user