Do not suggest adding !! on null constant #KT-14643 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
84418738a7
commit
66bd9d63dd
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isNullExpression
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -106,7 +107,10 @@ class AddExclExclCallFix(psiElement: PsiElement, val checkImplicitReceivers: Boo
|
||||
|
||||
private fun getExpressionForIntroduceCall(): ExpressionForCall? {
|
||||
val psiElement = element ?: return null
|
||||
return if (psiElement is LeafPsiElement && psiElement.elementType == KtTokens.DOT) {
|
||||
return if ((psiElement as? KtExpression).isNullExpression()) {
|
||||
return null
|
||||
}
|
||||
else if (psiElement is LeafPsiElement && psiElement.elementType == KtTokens.DOT) {
|
||||
(psiElement.prevSibling as? KtExpression).expressionForCall()
|
||||
}
|
||||
else if (psiElement is KtArrayAccessExpression) {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Add non-null asserted (!!) call" "false"
|
||||
// ACTION: Add 'const' modifier
|
||||
// ACTION: Add 'toString()' call
|
||||
// ACTION: Change type of 'x' to 'String?'
|
||||
// ACTION: Convert property initializer to getter
|
||||
// ERROR: Null can not be a value of a non-null type String
|
||||
|
||||
val x: String = null<caret>
|
||||
@@ -266,6 +266,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("null.kt")
|
||||
public void testNull() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/addExclExclCall/null.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("operationIn.kt")
|
||||
public void testOperationIn() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/addExclExclCall/operationIn.kt");
|
||||
|
||||
Reference in New Issue
Block a user