From 6baf633a8d16b27e4ed874f2e99f6eccf4095251 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Wed, 21 Sep 2016 23:02:05 +0300 Subject: [PATCH] Fixed bug found because of incorrect test fixed --- .../loopToCallChain/sequence/FilterTransformation.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/FilterTransformation.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/FilterTransformation.kt index 4aedd0abb31..7482dd46f43 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/FilterTransformation.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/sequence/FilterTransformation.kt @@ -115,6 +115,10 @@ class FilterTransformation( val condition = ifStatement.condition ?: return null val then = ifStatement.then ?: return null + // we do not allow filter() which uses neither input variable nor index variable (though is technically possible but looks confusing) + // shouldUseInputVariables = false does not work for us because we sometimes return Result match in this matcher + if (!state.inputVariable.hasUsages(condition) && (state.indexVariable == null || !state.indexVariable.hasUsages(condition))) return null + if (state.statements.size == 1) { val transformation = createFilterTransformation(state.outerLoop, state.inputVariable, state.indexVariable, condition, isInverse = false) val newState = state.copy(statements = listOf(then))