Add non-null assertion: correct handling of unary expression unsafe calls #KT-13430 Fixed
This commit is contained in:
@@ -98,6 +98,13 @@ class AddExclExclCallFix(val psiElement: PsiElement) : ExclExclCallFix() {
|
|||||||
else if (psiElement is KtArrayAccessExpression) {
|
else if (psiElement is KtArrayAccessExpression) {
|
||||||
return psiElement.arrayExpression
|
return psiElement.arrayExpression
|
||||||
}
|
}
|
||||||
|
else if (psiElement is KtOperationReferenceExpression) {
|
||||||
|
val parent = psiElement.parent
|
||||||
|
return when (parent) {
|
||||||
|
is KtUnaryExpression -> parent.baseExpression
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (psiElement is KtExpression) {
|
else if (psiElement is KtExpression) {
|
||||||
return psiElement
|
return psiElement
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// "Add non-null asserted (!!) call" "true"
|
||||||
|
|
||||||
|
class SafeType {
|
||||||
|
operator fun unaryMinus() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun safeB(p: SafeType?) {
|
||||||
|
val v = <caret>-p
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// "Add non-null asserted (!!) call" "true"
|
||||||
|
|
||||||
|
class SafeType {
|
||||||
|
operator fun unaryMinus() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun safeB(p: SafeType?) {
|
||||||
|
val v = -p!!
|
||||||
|
}
|
||||||
@@ -4782,6 +4782,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("fixNullableUnaryWithExclExcl.kt")
|
||||||
|
public void testFixNullableUnaryWithExclExcl() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/expressions/fixNullableUnaryWithExclExcl.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("fixNullableWithExclExclAbsentWithBadIterator.kt")
|
@TestMetadata("fixNullableWithExclExclAbsentWithBadIterator.kt")
|
||||||
public void testFixNullableWithExclExclAbsentWithBadIterator() throws Exception {
|
public void testFixNullableWithExclExclAbsentWithBadIterator() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/expressions/fixNullableWithExclExclAbsentWithBadIterator.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/expressions/fixNullableWithExclExclAbsentWithBadIterator.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user