Report interop functions with non-stable parameter names

^KT-34602
This commit is contained in:
Dmitriy Dolovov
2020-07-22 17:32:22 +07:00
parent 3d9093583f
commit b47946cbba
9 changed files with 217 additions and 9 deletions
@@ -714,7 +714,8 @@ public interface Errors {
DiagnosticFactory1<PsiElement, BadNamedArgumentsTarget> NAMED_ARGUMENTS_NOT_ALLOWED = DiagnosticFactory1.create(ERROR);
enum BadNamedArgumentsTarget {
NON_KOTLIN_FUNCTION,
NON_KOTLIN_FUNCTION, // a function provided by non-Kotlin artifact, ex: Java function
INTEROP_FUNCTION, // deserialized Kotlin function that serves as a bridge to a function written in another language, ex: Obj-C
INVOKE_ON_FUNCTION_TYPE,
EXPECTED_CLASS_MEMBER,
}
@@ -197,6 +197,8 @@ public class DefaultErrorMessages {
switch (target) {
case NON_KOTLIN_FUNCTION:
return "non-Kotlin functions";
case INTEROP_FUNCTION:
return "interop functions with ambiguous parameter names";
case INVOKE_ON_FUNCTION_TYPE:
return "function types";
case EXPECTED_CLASS_MEMBER:
@@ -11,8 +11,7 @@ import org.jetbrains.kotlin.builtins.isExtensionFunctionType
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.diagnostics.Errors.*
import org.jetbrains.kotlin.diagnostics.Errors.BadNamedArgumentsTarget.INVOKE_ON_FUNCTION_TYPE
import org.jetbrains.kotlin.diagnostics.Errors.BadNamedArgumentsTarget.NON_KOTLIN_FUNCTION
import org.jetbrains.kotlin.diagnostics.Errors.BadNamedArgumentsTarget.*
import org.jetbrains.kotlin.diagnostics.reportDiagnosticOnce
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.isNull
@@ -32,6 +31,7 @@ import org.jetbrains.kotlin.resolve.constants.TypedCompileTimeConstant
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
import org.jetbrains.kotlin.resolve.descriptorUtil.module
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.checker.intersectWrappedTypes
import org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils
@@ -260,7 +260,11 @@ class DiagnosticReporterByTrackingStrategy(
NamedArgumentNotAllowed::class.java -> trace.report(
NAMED_ARGUMENTS_NOT_ALLOWED.on(
nameReference,
if ((diagnostic as NamedArgumentNotAllowed).descriptor is FunctionInvokeDescriptor) INVOKE_ON_FUNCTION_TYPE else NON_KOTLIN_FUNCTION
when ((diagnostic as NamedArgumentNotAllowed).descriptor) {
is FunctionInvokeDescriptor -> INVOKE_ON_FUNCTION_TYPE
is DeserializedCallableMemberDescriptor -> INTEROP_FUNCTION
else -> NON_KOTLIN_FUNCTION
}
)
)
ArgumentPassedTwice::class.java -> trace.report(ARGUMENT_PASSED_TWICE.on(nameReference))
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
import org.jetbrains.kotlin.resolve.calls.components.ArgumentsUtilsKt;
import org.jetbrains.kotlin.resolve.calls.model.*;
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy;
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor;
import java.util.*;
@@ -185,10 +186,16 @@ public class ValueArgumentsToParametersMapper {
report(NAMED_ARGUMENTS_NOT_ALLOWED.on(nameReference, EXPECTED_CLASS_MEMBER));
}
else if (!candidate.hasStableParameterNames()) {
report(NAMED_ARGUMENTS_NOT_ALLOWED.on(
nameReference,
candidate instanceof FunctionInvokeDescriptor ? INVOKE_ON_FUNCTION_TYPE : NON_KOTLIN_FUNCTION
));
BadNamedArgumentsTarget badNamedArgumentsTarget;
if (candidate instanceof FunctionInvokeDescriptor) {
badNamedArgumentsTarget = INVOKE_ON_FUNCTION_TYPE;
} else if (candidate instanceof DeserializedCallableMemberDescriptor) {
badNamedArgumentsTarget = INTEROP_FUNCTION;
} else {
badNamedArgumentsTarget = NON_KOTLIN_FUNCTION;
}
report(NAMED_ARGUMENTS_NOT_ALLOWED.on(nameReference, badNamedArgumentsTarget));
}
}