IDE: Don't add this!! in AddExclExclCallFix for nullable member

access in extension function.

^KTIJ-10052 Fixed
This commit is contained in:
Mark Punzalan
2021-04-23 05:02:06 +00:00
committed by Ilya Kirillov
parent c0fbdb1535
commit c472c9facd
13 changed files with 113 additions and 2 deletions
@@ -174,6 +174,6 @@ object MissingIteratorExclExclFixFactory : KotlinSingleIntentionActionFactory()
else -> return null
}
return AddExclExclCallFix(element)
return AddExclExclCallFix(element, checkImplicitReceivers = false)
}
}
@@ -166,7 +166,7 @@ class QuickFixFactoryForTypeMismatchError : KotlinIntentionActionsFactory() {
val nullableExpected = expectedType.makeNullable()
if (expressionType.isSubtypeOf(nullableExpected)) {
val targetExpression = diagnosticElement.getTopMostQualifiedForSelectorIfAny()
actions.add(AddExclExclCallFix(targetExpression))
actions.add(AddExclExclCallFix(targetExpression, checkImplicitReceivers = false))
if (expectedType.isBoolean()) {
actions.add(AddEqEqTrueFix(targetExpression))
}
+6
View File
@@ -0,0 +1,6 @@
// "Add non-null asserted (!!) call" "true"
// WITH_RUNTIME
fun foo(a: List<String>?) {
for (s in <caret>a) {}
}
@@ -0,0 +1,6 @@
// "Add non-null asserted (!!) call" "true"
// WITH_RUNTIME
fun foo(a: List<String>?) {
for (s in a!!) {}
}
@@ -0,0 +1,11 @@
// "Add non-null asserted (!!) call" "true"
// WITH_RUNTIME
class C {
val list: List<String>? = null
}
// Test for KTIJ-10052
fun C.test() {
for (s in <caret>list) {}
}
@@ -0,0 +1,11 @@
// "Add non-null asserted (!!) call" "true"
// WITH_RUNTIME
class C {
val list: List<String>? = null
}
// Test for KTIJ-10052
fun C.test() {
for (s in list!!) {}
}
@@ -0,0 +1,5 @@
// "Add non-null asserted (!!) call" "true"
fun test() {
val s: String? = null
val z: String = <caret>s
}
@@ -0,0 +1,5 @@
// "Add non-null asserted (!!) call" "true"
fun test() {
val s: String? = null
val z: String = s!!
}
@@ -0,0 +1,12 @@
// "Add non-null asserted (!!) call" "true"
class C {
val s: String? = null
}
// Test for KTIJ-10052
fun C.test() {
other(<caret>s)
}
fun other(s: String) {}
@@ -0,0 +1,12 @@
// "Add non-null asserted (!!) call" "true"
class C {
val s: String? = null
}
// Test for KTIJ-10052
fun C.test() {
other(s!!)
}
fun other(s: String) {}
@@ -0,0 +1,9 @@
// "Add non-null asserted (!!) call" "true"
class C {
val s: String? = null
}
// Test for KTIJ-10052
fun C.test() {
val z: String = <caret>s
}
@@ -0,0 +1,9 @@
// "Add non-null asserted (!!) call" "true"
class C {
val s: String? = null
}
// Test for KTIJ-10052
fun C.test() {
val z: String = s!!
}
@@ -677,6 +677,16 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
runTest("idea/testData/quickfix/addExclExclCall/implicitFunctionCall.kt");
}
@TestMetadata("iterable.kt")
public void testIterable() throws Exception {
runTest("idea/testData/quickfix/addExclExclCall/iterable.kt");
}
@TestMetadata("iterableInExtension.kt")
public void testIterableInExtension() throws Exception {
runTest("idea/testData/quickfix/addExclExclCall/iterableInExtension.kt");
}
@TestMetadata("normal.kt")
public void testNormal() throws Exception {
runTest("idea/testData/quickfix/addExclExclCall/normal.kt");
@@ -13776,6 +13786,21 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
runTest("idea/testData/quickfix/typeMismatch/addArrayOfTypeForNamedParameter.kt");
}
@TestMetadata("addExclExclToAssignmentRValue.kt")
public void testAddExclExclToAssignmentRValue() throws Exception {
runTest("idea/testData/quickfix/typeMismatch/addExclExclToAssignmentRValue.kt");
}
@TestMetadata("addExclExclToMemberAccessInExtension.kt")
public void testAddExclExclToMemberAccessInExtension() throws Exception {
runTest("idea/testData/quickfix/typeMismatch/addExclExclToMemberAccessInExtension.kt");
}
@TestMetadata("addExclExclToMemberAccessInExtensionAsAssignmentRValue.kt")
public void testAddExclExclToMemberAccessInExtensionAsAssignmentRValue() throws Exception {
runTest("idea/testData/quickfix/typeMismatch/addExclExclToMemberAccessInExtensionAsAssignmentRValue.kt");
}
@TestMetadata("addExclExclToQualifiedArgument.kt")
public void testAddExclExclToQualifiedArgument() throws Exception {
runTest("idea/testData/quickfix/typeMismatch/addExclExclToQualifiedArgument.kt");