Replace with safe calls forbidden for comparisons #KT-13432 Fixed
This commit is contained in:
@@ -91,8 +91,7 @@ class ReplaceInfixOrOperatorCallFix(element: KtExpression) : KotlinQuickFixActio
|
|||||||
is KtBinaryExpression -> {
|
is KtBinaryExpression -> {
|
||||||
if (parent.left == null || parent.right == null) null
|
if (parent.left == null || parent.right == null) null
|
||||||
else {
|
else {
|
||||||
if (parent.operationToken in OperatorConventions.COMPARISON_OPERATIONS &&
|
if (parent.operationToken in OperatorConventions.COMPARISON_OPERATIONS) null
|
||||||
parent.analyze()[BindingContext.EXPECTED_EXPRESSION_TYPE, parent]?.isBoolean() ?: false) null
|
|
||||||
else ReplaceInfixOrOperatorCallFix(parent)
|
else ReplaceInfixOrOperatorCallFix(parent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// "Replace with safe (?.) call" "false"
|
||||||
|
// ERROR: Infix call corresponds to a dot-qualified call 'p1.compareTo(p2)' which is not allowed on a nullable receiver 'p1'. Use '?.'-qualified call instead
|
||||||
|
// ACTION: Add non-null asserted (!!) call
|
||||||
|
// ACTION: Flip '>'
|
||||||
|
// ACTION: Replace overloaded operator with function call
|
||||||
|
|
||||||
|
class SafeType {
|
||||||
|
operator fun compareTo(other : SafeType) = 0
|
||||||
|
}
|
||||||
|
fun safeA(p1: SafeType?, p2: SafeType) {
|
||||||
|
val v8 = p1 <caret>> p2
|
||||||
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
// "Replace with safe (?.) call" "true"
|
|
||||||
// ERROR: Infix call corresponds to a dot-qualified call 'value?.compareTo(1).compareTo(0)' which is not allowed on a nullable receiver 'value?.compareTo(1)'. Use '?.'-qualified call instead
|
|
||||||
var foo: Int? = null
|
|
||||||
set(value) {
|
|
||||||
if((value <caret>< 1) ?: false) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
// "Replace with safe (?.) call" "true"
|
|
||||||
// ERROR: Infix call corresponds to a dot-qualified call 'value?.compareTo(1).compareTo(0)' which is not allowed on a nullable receiver 'value?.compareTo(1)'. Use '?.'-qualified call instead
|
|
||||||
var foo: Int? = null
|
|
||||||
set(value) {
|
|
||||||
if((value?.compareTo(1) < 0) ?: false) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6174,9 +6174,9 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/nullables/unsafeInfixCall"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/nullables/unsafeInfixCall"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("operator.kt")
|
@TestMetadata("noComparison.kt")
|
||||||
public void testOperator() throws Exception {
|
public void testNoComparison() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/nullables/unsafeInfixCall/operator.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/nullables/unsafeInfixCall/noComparison.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user