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 -> {
|
||||
if (parent.left == null || parent.right == null) null
|
||||
else {
|
||||
if (parent.operationToken in OperatorConventions.COMPARISON_OPERATIONS &&
|
||||
parent.analyze()[BindingContext.EXPECTED_EXPRESSION_TYPE, parent]?.isBoolean() ?: false) null
|
||||
if (parent.operationToken in OperatorConventions.COMPARISON_OPERATIONS) null
|
||||
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);
|
||||
}
|
||||
|
||||
@TestMetadata("operator.kt")
|
||||
public void testOperator() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/nullables/unsafeInfixCall/operator.kt");
|
||||
@TestMetadata("noComparison.kt")
|
||||
public void testNoComparison() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/nullables/unsafeInfixCall/noComparison.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user