[NI] Fix reporting UNSAFE_IMPLICIT_INVOKE_CALL diagnostic

This commit is contained in:
Dmitriy Novozhilov
2019-04-25 17:59:20 +03:00
committed by Mikhail Zarechenskiy
parent 251a02f71d
commit e6deaf3315
10 changed files with 56 additions and 5 deletions
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.resolve.calls
import org.jetbrains.kotlin.builtins.functions.FunctionInvokeDescriptor
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.diagnostics.Errors.*
import org.jetbrains.kotlin.diagnostics.Errors.BadNamedArgumentsTarget.INVOKE_ON_FUNCTION_TYPE
@@ -86,7 +87,8 @@ class DiagnosticReporterByTrackingStrategy(
override fun onCallReceiver(callReceiver: SimpleKotlinCallArgument, diagnostic: KotlinCallDiagnostic) {
when (diagnostic.javaClass) {
UnsafeCallError::class.java -> {
val implicitInvokeCheck = (callReceiver as? ReceiverExpressionKotlinCallArgument)?.isForImplicitInvoke ?: false
val implicitInvokeCheck = (callReceiver as? ReceiverExpressionKotlinCallArgument)?.isForImplicitInvoke
?: callReceiver.receiver.receiverValue.type.isExtensionFunctionType
tracingStrategy.unsafeCall(trace, callReceiver.receiver.receiverValue.type, implicitInvokeCheck)
}
@@ -540,10 +540,12 @@ class PSICallResolver(
resolvedArgumentsInParenthesis.forEach { it.setResultDataFlowInfoIfRelevant(resultDataFlowInfo) }
astExternalArgument?.setResultDataFlowInfoIfRelevant(resultDataFlowInfo)
val isForImplicitInvoke = oldCall is CallTransformer.CallForImplicitInvoke
return PSIKotlinCallImpl(
kotlinCallKind, oldCall, tracingStrategy, resolvedExplicitReceiver, dispatchReceiverForInvoke, name,
resolvedTypeArguments, resolvedArgumentsInParenthesis, astExternalArgument, context.dataFlowInfo, resultDataFlowInfo,
context.dataFlowInfoForArguments
context.dataFlowInfoForArguments, isForImplicitInvoke
)
}
@@ -65,7 +65,8 @@ class PSIKotlinCallImpl(
override val externalArgument: KotlinCallArgument?,
override val startingDataFlowInfo: DataFlowInfo,
override val resultDataFlowInfo: DataFlowInfo,
override val dataFlowInfoForArguments: DataFlowInfoForArguments
override val dataFlowInfoForArguments: DataFlowInfoForArguments,
override val isForImplicitInvoke: Boolean
) : PSIKotlinCall()
class PSIKotlinCallForVariable(
@@ -86,6 +87,8 @@ class PSIKotlinCallForVariable(
override val psiCall: Call = CallTransformer.stripCallArguments(baseCall.psiCall).let {
if (explicitReceiver == null) CallTransformer.stripReceiver(it) else it
}
override val isForImplicitInvoke: Boolean get() = false
}
class PSIKotlinCallForInvoke(
@@ -105,6 +108,7 @@ class PSIKotlinCallForInvoke(
override val dataFlowInfoForArguments: DataFlowInfoForArguments get() = baseCall.dataFlowInfoForArguments
override val psiCall: Call
override val tracingStrategy: TracingStrategy
override val isForImplicitInvoke: Boolean = true
init {
val variableReceiver = dispatchReceiverForInvokeExtension ?: explicitReceiver