Fix 'infix call' diagnostic for in operation
#KT-8845 Fixed
This commit is contained in:
@@ -784,7 +784,8 @@ public interface Errors {
|
||||
|
||||
DiagnosticFactory1<PsiElement, KotlinType> UNSAFE_CALL = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, KotlinType> UNSAFE_IMPLICIT_INVOKE_CALL = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory3<KtExpression, String, String, String> UNSAFE_INFIX_CALL = DiagnosticFactory3.create(ERROR);
|
||||
DiagnosticFactory3<KtExpression, PsiElement, String, PsiElement> UNSAFE_INFIX_CALL = DiagnosticFactory3.create(ERROR);
|
||||
DiagnosticFactory3<KtExpression, PsiElement, String, PsiElement> UNSAFE_OPERATOR_CALL = DiagnosticFactory3.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, KotlinType> UNNECESSARY_SAFE_CALL = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactory0<PsiElement> UNEXPECTED_SAFE_CALL = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, KotlinType> UNNECESSARY_NOT_NULL_ASSERTION = DiagnosticFactory1.create(WARNING);
|
||||
|
||||
+4
-1
@@ -717,7 +717,10 @@ public class DefaultErrorMessages {
|
||||
MAP.put(UNSAFE_INFIX_CALL,
|
||||
"Infix call corresponds to a dot-qualified call ''{0}.{1}({2})'' which is not allowed on a nullable receiver ''{0}''. " +
|
||||
"Use ''?.''-qualified call instead",
|
||||
STRING, STRING, STRING);
|
||||
ELEMENT_TEXT, STRING, ELEMENT_TEXT);
|
||||
MAP.put(UNSAFE_OPERATOR_CALL,
|
||||
"Operator call corresponds to a dot-qualified call ''{0}.{1}({2})'' which is not allowed on a nullable receiver ''{0}''.",
|
||||
ELEMENT_TEXT, STRING, ELEMENT_TEXT);
|
||||
|
||||
MAP.put(OVERLOAD_RESOLUTION_AMBIGUITY, "Overload resolution ambiguity: {0}", AMBIGUOUS_CALLS);
|
||||
MAP.put(NONE_APPLICABLE, "None of the following functions can be called with the arguments supplied: {0}", AMBIGUOUS_CALLS);
|
||||
|
||||
+26
-13
@@ -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.
|
||||
@@ -173,18 +173,7 @@ public abstract class AbstractTracingStrategy implements TracingStrategy {
|
||||
else {
|
||||
PsiElement callElement = call.getCallElement();
|
||||
if (callElement instanceof KtBinaryExpression) {
|
||||
KtBinaryExpression binaryExpression = (KtBinaryExpression)callElement;
|
||||
KtSimpleNameExpression operationReference = binaryExpression.getOperationReference();
|
||||
|
||||
Name operationString = operationReference.getReferencedNameElementType() == KtTokens.IDENTIFIER ?
|
||||
Name.identifier(operationReference.getText()) :
|
||||
OperatorConventions.getNameForOperationSymbol((KtToken) operationReference.getReferencedNameElementType());
|
||||
|
||||
KtExpression left = binaryExpression.getLeft();
|
||||
KtExpression right = binaryExpression.getRight();
|
||||
if (left != null && right != null) {
|
||||
trace.report(UNSAFE_INFIX_CALL.on(reference, left.getText(), operationString.asString(), right.getText()));
|
||||
}
|
||||
reportUnsafeCallOnBinaryExpression(trace, (KtBinaryExpression) callElement);
|
||||
}
|
||||
else if (isCallForImplicitInvoke) {
|
||||
trace.report(UNSAFE_IMPLICIT_INVOKE_CALL.on(reference, type));
|
||||
@@ -195,6 +184,30 @@ public abstract class AbstractTracingStrategy implements TracingStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
private void reportUnsafeCallOnBinaryExpression(@NotNull BindingTrace trace, @NotNull KtBinaryExpression binaryExpression) {
|
||||
KtSimpleNameExpression operationReference = binaryExpression.getOperationReference();
|
||||
boolean isInfixCall = operationReference.getReferencedNameElementType() == KtTokens.IDENTIFIER;
|
||||
Name operationString = isInfixCall ?
|
||||
Name.identifier(operationReference.getText()) :
|
||||
OperatorConventions.getNameForOperationSymbol((KtToken) operationReference.getReferencedNameElementType());
|
||||
|
||||
if (operationString == null) return;
|
||||
|
||||
KtExpression left = binaryExpression.getLeft();
|
||||
KtExpression right = binaryExpression.getRight();
|
||||
if (left == null || right == null) return;
|
||||
|
||||
if (isInfixCall) {
|
||||
trace.report(UNSAFE_INFIX_CALL.on(reference, left, operationString.asString(), right));
|
||||
}
|
||||
else {
|
||||
boolean inOperation = KtPsiUtil.isInOrNotInOperation(binaryExpression);
|
||||
KtExpression receiver = inOperation ? right : left;
|
||||
KtExpression argument = inOperation ? left : right;
|
||||
trace.report(UNSAFE_OPERATOR_CALL.on(reference, receiver, operationString.asString(), argument));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invisibleMember(@NotNull BindingTrace trace, @NotNull DeclarationDescriptorWithVisibility descriptor) {
|
||||
trace.report(INVISIBLE_MEMBER.on(call.getCallElement(), descriptor, descriptor.getVisibility(), descriptor));
|
||||
|
||||
Reference in New Issue
Block a user