Use receivers from candidate as a fallback during completion of callable references

^KT-45083 Fixed
This commit is contained in:
Victor Petukhov
2021-06-03 17:03:58 +03:00
committed by TeamCityServer
parent fe8f7cfcae
commit 750f327878
2 changed files with 29 additions and 5 deletions
@@ -403,15 +403,20 @@ class ResolvedAtomCompleter(
callableCandidate: CallableReferenceCandidate, callableCandidate: CallableReferenceCandidate,
recordedDescriptor: CallableDescriptor recordedDescriptor: CallableDescriptor
): CallableReferenceResultTypeInfo { ): CallableReferenceResultTypeInfo {
val dispatchReceiver = recordedDescriptor.dispatchReceiverParameter?.value
?: callableCandidate.dispatchReceiver?.receiver?.receiverValue
val extensionReceiver = recordedDescriptor.extensionReceiverParameter?.value
?: callableCandidate.extensionReceiver?.receiver?.receiverValue
val explicitCallableReceiver = when (callableCandidate.explicitReceiverKind) { val explicitCallableReceiver = when (callableCandidate.explicitReceiverKind) {
ExplicitReceiverKind.DISPATCH_RECEIVER -> callableCandidate.dispatchReceiver ExplicitReceiverKind.DISPATCH_RECEIVER -> dispatchReceiver
ExplicitReceiverKind.EXTENSION_RECEIVER -> callableCandidate.extensionReceiver ExplicitReceiverKind.EXTENSION_RECEIVER -> extensionReceiver
else -> null else -> null
} }
return CallableReferenceResultTypeInfo( return CallableReferenceResultTypeInfo(
recordedDescriptor.dispatchReceiverParameter?.value, dispatchReceiver,
recordedDescriptor.extensionReceiverParameter?.value, extensionReceiver,
explicitCallableReceiver?.receiver?.receiverValue, explicitCallableReceiver,
TypeSubstitutor.EMPTY, TypeSubstitutor.EMPTY,
callableCandidate.reflectionCandidateType.replaceFunctionTypeArgumentsByDescriptor(recordedDescriptor) callableCandidate.reflectionCandidateType.replaceFunctionTypeArgumentsByDescriptor(recordedDescriptor)
) )
@@ -0,0 +1,19 @@
// WITH_RUNTIME
// DONT_TARGET_EXACT_BACKEND: WASM
import kotlin.experimental.ExperimentalTypeInference
object Hello {
val hello = "hello"
}
@OptIn(ExperimentalTypeInference::class)
fun <E> buildList0(@BuilderInference builder: MutableList<E>.() -> Unit): List<E> = mutableListOf<E>().apply { builder() }
val numbers = buildList0 {
add(Hello.let { it::hello }.get())
}
fun box(): String {
numbers
return "OK"
}