[NI] Fix exception explicit qualified receiver and dispatch receiver

This commit is contained in:
Mikhail Zarechenskiy
2017-08-11 12:17:25 +03:00
committed by Stanislav Erokhin
parent 9f71de5f66
commit f42be4aea2
7 changed files with 51 additions and 11 deletions
@@ -313,7 +313,7 @@ class PSICallResolver(
val variableCallArgument = createReceiverCallArgument(variable)
val explicitReceiver = kotlinCall.explicitReceiver
val callForInvoke = if (useExplicitReceiver && explicitReceiver is SimpleKotlinCallArgument) {
val callForInvoke = if (useExplicitReceiver && explicitReceiver != null) {
PSIKotlinCallForInvoke(kotlinCall, variable, explicitReceiver, variableCallArgument)
}
else {
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategyForInvoke
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.util.OperatorNameConventions
val KotlinCall.psiKotlinCall: PSIKotlinCall get() {
@@ -80,7 +81,7 @@ class PSIKotlinCallForVariable(
class PSIKotlinCallForInvoke(
val baseCall: PSIKotlinCallImpl,
val variableCall: KotlinResolutionCandidate,
override val explicitReceiver: SimpleKotlinCallArgument,
override val explicitReceiver: ReceiverKotlinCallArgument,
override val dispatchReceiverForInvokeExtension: SimpleKotlinCallArgument?
) : PSIKotlinCall() {
override val callKind: KotlinCallKind get() = KotlinCallKind.FUNCTION
@@ -101,8 +102,15 @@ class PSIKotlinCallForInvoke(
val calleeExpression = baseCall.psiCall.calleeExpression!!
psiCall = CallTransformer.CallForImplicitInvoke(
explicitExtensionReceiver?.receiver?.receiverValue,
variableReceiver.receiver.receiverValue as ExpressionReceiver, baseCall.psiCall, true)
tracingStrategy = TracingStrategyForInvoke(calleeExpression, psiCall, variableReceiver.receiver.receiverValue.type)
explicitExtensionReceiver?.receiverValue,
variableReceiver.receiverValue as ExpressionReceiver, baseCall.psiCall, true)
tracingStrategy = TracingStrategyForInvoke(calleeExpression, psiCall, variableReceiver.receiverValue!!.type) // check for type parameters
}
}
val ReceiverKotlinCallArgument.receiverValue: ReceiverValue?
get() = when (this) {
is SimpleKotlinCallArgument -> this.receiver.receiverValue
is QualifierReceiverKotlinCallArgument -> this.receiver.classValueReceiver
else -> null
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.resolve.calls.model
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
interface KotlinCall : ResolutionAtom {
@@ -25,7 +26,7 @@ interface KotlinCall : ResolutionAtom {
val explicitReceiver: ReceiverKotlinCallArgument?
// a.(foo)() -- (foo) is dispatchReceiverForInvoke
val dispatchReceiverForInvokeExtension: SimpleKotlinCallArgument? get() = null
val dispatchReceiverForInvokeExtension: ReceiverKotlinCallArgument? get() = null
val name: Name
@@ -62,8 +63,8 @@ fun KotlinCall.checkCallInvariants() {
"Lambda argument or callable reference is not allowed as explicit receiver: $explicitReceiver"
}
(explicitReceiver as? SimpleKotlinCallArgument)?.checkReceiverInvariants()
dispatchReceiverForInvokeExtension?.checkReceiverInvariants()
explicitReceiver.safeAs<SimpleKotlinCallArgument>()?.checkReceiverInvariants()
dispatchReceiverForInvokeExtension.safeAs<SimpleKotlinCallArgument>()?.checkReceiverInvariants()
argumentsInParenthesis.forEach(KotlinCallArgument::checkArgumentInvariants)
externalArgument?.checkArgumentInvariants()
@@ -28,9 +28,13 @@ import org.jetbrains.kotlin.types.UnwrappedType
interface ReceiverKotlinCallArgument : KotlinCallArgument {
val receiver: DetailedReceiver
val isSafeCall: Boolean
}
class QualifierReceiverKotlinCallArgument(override val receiver: QualifierReceiver) : ReceiverKotlinCallArgument {
override val isSafeCall: Boolean
get() = false // TODO: add warning
override fun toString() = "$receiver"
override val isSpread get() = false
@@ -46,8 +50,6 @@ interface PostponableKotlinCallArgument : KotlinCallArgument, ResolutionAtom
interface SimpleKotlinCallArgument : KotlinCallArgument, ReceiverKotlinCallArgument {
override val receiver: ReceiverValueWithSmartCastInfo
val isSafeCall: Boolean
}
interface ExpressionKotlinCallArgument : SimpleKotlinCallArgument, ResolutionAtom
@@ -0,0 +1,7 @@
object X
class Y {
fun f(op: X.() -> Unit) {
X.op()
}
}
@@ -0,0 +1,16 @@
package
public object X {
private constructor X()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Y {
public constructor Y()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun f(/*0*/ op: X.() -> kotlin.Unit): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -17470,6 +17470,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("propertyWithExtensionTypeInvoke.kt")
public void testPropertyWithExtensionTypeInvoke() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/propertyWithExtensionTypeInvoke.kt");
doTest(fileName);
}
@TestMetadata("resolveSubclassOfList.kt")
public void testResolveSubclassOfList() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/resolveSubclassOfList.kt");