Add non-null assertion: correct handling of unary expression unsafe calls #KT-13430 Fixed

This commit is contained in:
Mikhail Glukhikh
2016-08-12 15:51:23 +03:00
parent 13975778c5
commit cf2d575eec
4 changed files with 31 additions and 0 deletions
@@ -98,6 +98,13 @@ class AddExclExclCallFix(val psiElement: PsiElement) : ExclExclCallFix() {
else if (psiElement is KtArrayAccessExpression) {
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) {
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);
}
@TestMetadata("fixNullableUnaryWithExclExcl.kt")
public void testFixNullableUnaryWithExclExcl() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/expressions/fixNullableUnaryWithExclExcl.kt");
doTest(fileName);
}
@TestMetadata("fixNullableWithExclExclAbsentWithBadIterator.kt")
public void testFixNullableWithExclExclAbsentWithBadIterator() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/expressions/fixNullableWithExclExclAbsentWithBadIterator.kt");