KT-11594 "Add non-null asserted (!!) call" applied to unsafe cast to nullable type causes AE at KtPsiFactory.createExpression()

#KT-11594 Fixed
This commit is contained in:
Valentin Kipyatkov
2016-04-07 20:53:47 +03:00
parent b5e89713cd
commit a68dbe78d8
4 changed files with 22 additions and 5 deletions
@@ -31,10 +31,7 @@ import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtPostfixExpression
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.util.OperatorNameConventions import org.jetbrains.kotlin.util.OperatorNameConventions
@@ -85,7 +82,7 @@ class AddExclExclCallFix(val psiElement: PsiElement) : ExclExclCallFix() {
override fun invoke(project: Project, editor: Editor?, file: PsiFile?) { override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {
val modifiedExpression = getExpressionForIntroduceCall() ?: return val modifiedExpression = getExpressionForIntroduceCall() ?: return
val exclExclExpression = KtPsiFactory(project).createExpression(modifiedExpression.text + "!!") val exclExclExpression = KtPsiFactory(project).createExpressionByPattern("$0!!", modifiedExpression)
modifiedExpression.replace(exclExclExpression) modifiedExpression.replace(exclExclExpression)
} }
+7
View File
@@ -0,0 +1,7 @@
// "Add non-null asserted (!!) call" "true"
fun callMe(p: String) {}
fun callIt(p: Any) {
callMe(<caret>p as String?)
}
+7
View File
@@ -0,0 +1,7 @@
// "Add non-null asserted (!!) call" "true"
fun callMe(p: String) {}
fun callIt(p: Any) {
callMe(<caret>(p as String?)!!)
}
@@ -4473,6 +4473,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest(fileName); doTest(fileName);
} }
@TestMetadata("kt11594.kt")
public void testKt11594() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/expressions/kt11594.kt");
doTest(fileName);
}
@TestMetadata("removeUselessCast.kt") @TestMetadata("removeUselessCast.kt")
public void testRemoveUselessCast() throws Exception { public void testRemoveUselessCast() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/expressions/removeUselessCast.kt"); String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/expressions/removeUselessCast.kt");