From f21f23744ed1a018edc674e9d786230c0aecb81f Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Mon, 22 Aug 2016 16:35:05 +0300 Subject: [PATCH] Hopefully fixed EA-87200 - TCE: UtilsKt.tryChangeAndCheckErrors #EA-87200 Fixed --- .../idea/intentions/loopToCallChain/matchAndConvert.kt | 1 + .../kotlin/idea/intentions/loopToCallChain/utils.kt | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) 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 14919692200..ee30a592a38 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/matchAndConvert.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/matchAndConvert.kt @@ -247,6 +247,7 @@ private fun isExpressionTypeSupported(expression: KtExpression): Boolean { private fun checkSmartCastsPreserved(loop: KtForExpression, matchResult: MatchResult): Boolean { val bindingContext = loop.analyze(BodyResolveMode.FULL) + // we declare these keys locally to avoid possible race-condition problems if this code is executed in 2 threads simultaneously val SMARTCAST_KEY = Key("SMARTCAST_KEY") val IMPLICIT_RECEIVER_SMARTCAST_KEY = Key("IMPLICIT_RECEIVER_SMARTCAST") diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/utils.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/utils.kt index d23e6d0fa87..9cd8439ccea 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/utils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/loopToCallChain/utils.kt @@ -228,9 +228,6 @@ fun canChangeLocalVariableType(variable: KtProperty, newTypeText: String, loop: } } -private val EXPRESSION = Key("EXPRESSION") -private val SCOPE_TO_EXCLUDE = Key("SCOPE_TO_EXCLUDE") - fun tryChangeAndCheckErrors( expressionToChange: TExpression, scopeToExclude: KtElement, @@ -244,6 +241,10 @@ fun tryChangeAndCheckErrors( .firstOrNull { bindingContext[BindingContext.USED_AS_EXPRESSION, it] != true } ?: return true + // we declare these keys locally to avoid possible race-condition problems if this code is executed in 2 threads simultaneously + val EXPRESSION = Key("EXPRESSION") + val SCOPE_TO_EXCLUDE = Key("SCOPE_TO_EXCLUDE") + expressionToChange.putCopyableUserData(EXPRESSION, Unit) scopeToExclude.putCopyableUserData(SCOPE_TO_EXCLUDE, Unit)