diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/caches/ValueWithPostCompute.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/caches/ValueWithPostCompute.kt index 3d2ac9ea5c1..b8f713a980d 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/caches/ValueWithPostCompute.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/caches/ValueWithPostCompute.kt @@ -27,7 +27,7 @@ internal class ValueWithPostCompute( private var _calculate: ((KEY) -> Pair)? = calculate private var _postCompute: ((KEY, VALUE, DATA) -> Unit)? = postCompute private var lock: ReentrantLock? = ReentrantLock() - private var guard: ThreadLocal? = ThreadLocal.withInitial { false } + private var guard: ThreadLocal? = ThreadLocal() /** * can be in one of the following three states: @@ -43,7 +43,8 @@ internal class ValueWithPostCompute( private var value: Any? = ValueIsNotComputed private inline fun recursiveGuarded(body: () -> T): T { - check(!guard!!.get()) { + val currentGuardValue = guard!!.get() + check(currentGuardValue == null || !currentGuardValue) { "Should not be called recursively" } guard!!.set(true)