Fix KNPE in introduce when expression (EA-118718)

This commit is contained in:
Andrey Uskov
2018-12-24 19:42:28 +03:00
parent 69613d25f0
commit bc71a7605a
3 changed files with 4 additions and 4 deletions
@@ -98,8 +98,8 @@ private fun KtExpression?.getWhenConditionSubjectCandidate(): KtExpression? {
}
}
fun KtWhenExpression.introduceSubject(): KtWhenExpression {
val subject = getSubjectToIntroduce()!!
fun KtWhenExpression.introduceSubject(): KtWhenExpression? {
val subject = getSubjectToIntroduce() ?: return null
val commentSaver = CommentSaver(this, saveLineBreaks = true)
@@ -192,7 +192,7 @@ class IfToWhenIntention : SelfTargetingRangeIntention<KtIfExpression>(KtIfExpres
if (whenExpression.getSubjectToIntroduce() != null) {
whenExpression = whenExpression.introduceSubject()
whenExpression = whenExpression.introduceSubject() ?: return
}
val result = ifExpression.replaced(whenExpression)
@@ -334,7 +334,7 @@ private fun makeCall(
val inlinableCall = controlFlow.outputValues.size <= 1
val unboxingExpressions =
if (inlinableCall) {
controlFlow.outputValueBoxer.getUnboxingExpressions(callText!!)
controlFlow.outputValueBoxer.getUnboxingExpressions(callText ?: return)
}
else {
val varNameValidator = NewDeclarationNameValidator(block, anchorInBlock, NewDeclarationNameValidator.Target.VARIABLES)