diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/matchAndConvert.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/matchAndConvert.kt index 172a9f77124..bbd358fa661 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/matchAndConvert.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/matchAndConvert.kt @@ -93,8 +93,6 @@ fun match(loop: KtForExpression, useLazySequence: Boolean): MatchResult? { if (match != null) { if (!inputVariableUsed && match.allTransformations.any { it.shouldUseInputVariable }) return null - state.previousTransformations += match.sequenceTransformations - when (match) { is TransformationMatch.Sequence -> { // check that old input variable is not needed anymore @@ -113,6 +111,7 @@ fun match(loop: KtForExpression, useLazySequence: Boolean): MatchResult? { if (countAfter != countBefore) continue@MatchersLoop // some embedded break or continue in the matched part } + state.previousTransformations += match.sequenceTransformations state = newState continue@MatchLoop } @@ -120,6 +119,8 @@ fun match(loop: KtForExpression, useLazySequence: Boolean): MatchResult? { is TransformationMatch.Result -> { if (restContainsEmbeddedBreakOrContinue && !matcher.embeddedBreakOrContinuePossible) continue@MatchersLoop + state.previousTransformations += match.sequenceTransformations + var result = TransformationMatch.Result(match.resultTransformation, state.previousTransformations) result = mergeTransformations(result)