Fix KCallable#name intrinsic for bound references
Do not skip generation of the left-hand side because it may produce side effects #KT-12995 Fixed
This commit is contained in:
+15
-5
@@ -19,23 +19,33 @@ package org.jetbrains.kotlin.codegen.intrinsics
|
||||
import org.jetbrains.kotlin.codegen.ExpressionCodegen
|
||||
import org.jetbrains.kotlin.codegen.StackValue
|
||||
import org.jetbrains.kotlin.psi.KtCallableReferenceExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext.DOUBLE_COLON_LHS
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes.JAVA_STRING_TYPE
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.types.expressions.DoubleColonLHS
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
import org.jetbrains.org.objectweb.asm.Type.VOID_TYPE
|
||||
|
||||
class KCallableNameProperty : IntrinsicPropertyGetter() {
|
||||
override fun generate(resolvedCall: ResolvedCall<*>?, codegen: ExpressionCodegen, returnType: Type, receiver: StackValue): StackValue? {
|
||||
val expressionReceiver = resolvedCall!!.dispatchReceiver as? ExpressionReceiver ?: return null
|
||||
val expression = expressionReceiver.expression as? KtCallableReferenceExpression ?: return null
|
||||
|
||||
val receiverExpression = expression.receiverExpression
|
||||
val lhs = receiverExpression?.let { codegen.bindingContext.get(DOUBLE_COLON_LHS, it) }
|
||||
|
||||
val callableReference = expression.callableReference
|
||||
val descriptor = callableReference.getResolvedCall(codegen.bindingContext)?.resultingDescriptor ?: return null
|
||||
val name = descriptor.name.asString()
|
||||
|
||||
return StackValue.operation(returnType) { iv ->
|
||||
iv.aconst(name)
|
||||
StackValue.coerce(AsmTypes.JAVA_STRING_TYPE, returnType, iv)
|
||||
// Generate the left-hand side of a bound callable reference expression
|
||||
if (lhs is DoubleColonLHS.Expression) {
|
||||
codegen.gen(receiverExpression, VOID_TYPE)
|
||||
}
|
||||
iv.aconst(descriptor.name.asString())
|
||||
StackValue.coerce(JAVA_STRING_TYPE, returnType, iv)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user