FIR: Report UNSAFE_INFIX_CALL for all infix-style calls, even if the
candidate is not an infix function. This mirrors FE 1.0 (see `AbstractTracingStrategy.reportUnsafeCallOnBinaryExpression()`) and allows consistent handling for quickfixes on infix calls.
This commit is contained in:
committed by
teamcityserver
parent
ca7649edbb
commit
6de1000818
+4
-6
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.lexer.KtTokens
|
|||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.*
|
import org.jetbrains.kotlin.resolve.calls.inference.model.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability
|
import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability
|
||||||
import org.jetbrains.kotlin.resolve.calls.tower.isSuccess
|
import org.jetbrains.kotlin.resolve.calls.tower.isSuccess
|
||||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
|
||||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
@@ -105,16 +104,15 @@ private fun mapUnsafeCallError(
|
|||||||
(candidateFunction?.isOperator == true || candidateFunction?.isInfix == true)
|
(candidateFunction?.isOperator == true || candidateFunction?.isInfix == true)
|
||||||
) {
|
) {
|
||||||
val operationToken = source.getChild(KtTokens.IDENTIFIER)
|
val operationToken = source.getChild(KtTokens.IDENTIFIER)
|
||||||
if (candidateFunction.isInfix && operationToken?.elementType == KtTokens.IDENTIFIER) {
|
return if (operationToken != null) {
|
||||||
return FirErrors.UNSAFE_INFIX_CALL.on(
|
FirErrors.UNSAFE_INFIX_CALL.on(
|
||||||
source,
|
source,
|
||||||
receiverExpression,
|
receiverExpression,
|
||||||
candidateFunctionName!!.asString(),
|
candidateFunctionName!!.asString(),
|
||||||
singleArgument,
|
singleArgument,
|
||||||
)
|
)
|
||||||
}
|
} else {
|
||||||
if (candidateFunction.isOperator && operationToken == null) {
|
FirErrors.UNSAFE_OPERATOR_CALL.on(
|
||||||
return FirErrors.UNSAFE_OPERATOR_CALL.on(
|
|
||||||
source,
|
source,
|
||||||
receiverExpression,
|
receiverExpression,
|
||||||
candidateFunctionName!!.asString(),
|
candidateFunctionName!!.asString(),
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ fun f(): Unit {
|
|||||||
var x: Int? = 1
|
var x: Int? = 1
|
||||||
x = null
|
x = null
|
||||||
x <!UNSAFE_OPERATOR_CALL!>+<!> 1
|
x <!UNSAFE_OPERATOR_CALL!>+<!> 1
|
||||||
x <!UNSAFE_CALL!>plus<!> 1
|
x <!UNSAFE_INFIX_CALL!>plus<!> 1
|
||||||
x <!UNSAFE_OPERATOR_CALL!><<!> 1
|
x <!UNSAFE_OPERATOR_CALL!><<!> 1
|
||||||
x <!UNRESOLVED_REFERENCE!>+=<!> 1
|
x <!UNRESOLVED_REFERENCE!>+=<!> 1
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
// "Replace with safe (?.) call" "true"
|
// "Replace with safe (?.) call" "true"
|
||||||
fun test(a : Int?) : Int? {
|
fun test(a : Int?) : Int? {
|
||||||
return a <caret>compareTo 6;
|
return a <caret>compareTo 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* IGNORE_FIR */
|
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
// "Replace with safe (?.) call" "true"
|
// "Replace with safe (?.) call" "true"
|
||||||
fun test(a : Int?) : Int? {
|
fun test(a : Int?) : Int? {
|
||||||
return a?.compareTo(6);
|
return a?.compareTo(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* IGNORE_FIR */
|
|
||||||
Reference in New Issue
Block a user