From 85c4d6b67b77828ad17218f0b3f65c51926f9d24 Mon Sep 17 00:00:00 2001 From: Marco Pennekamp Date: Mon, 18 Dec 2023 18:46:16 +0100 Subject: [PATCH] [FIR] Add workaround for exception in `JavaOverrideChecker.buildErasure` - `useMutableOrEmpty` causes the bounds to be replaced atomically, which avoids the race described in KT-60324. ^KT-60324 fixed ^KT-60445 --- .../fir/declarations/builder/FirTypeParameterBuilder.kt | 2 +- .../kotlin/fir/declarations/impl/FirTypeParameterImpl.kt | 5 ++--- .../jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt | 3 ++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirTypeParameterBuilder.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirTypeParameterBuilder.kt index 9854393854e..86d278f8de6 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirTypeParameterBuilder.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirTypeParameterBuilder.kt @@ -52,7 +52,7 @@ class FirTypeParameterBuilder : FirAnnotationContainerBuilder { containingDeclarationSymbol, variance, isReified, - bounds, + bounds.toMutableOrEmpty(), annotations.toMutableOrEmpty(), ) } diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirTypeParameterImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirTypeParameterImpl.kt index d93c3645a53..13f8421e37e 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirTypeParameterImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirTypeParameterImpl.kt @@ -37,7 +37,7 @@ internal class FirTypeParameterImpl( override val containingDeclarationSymbol: FirBasedSymbol<*>, override val variance: Variance, override val isReified: Boolean, - override val bounds: MutableList, + override var bounds: MutableOrEmptyList, override var annotations: MutableOrEmptyList, ) : FirTypeParameter() { @@ -63,8 +63,7 @@ internal class FirTypeParameterImpl( } override fun replaceBounds(newBounds: List) { - bounds.clear() - bounds.addAll(newBounds) + bounds = newBounds.toMutableOrEmpty() } override fun replaceAnnotations(newAnnotations: List) { diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt index e58a4d6b159..ee824bd9f7b 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt @@ -345,7 +345,8 @@ object NodeConfigurator : AbstractFieldConfigurator(FirTreeBuild } +field(varianceType) +booleanField("isReified") - +fieldList("bounds", typeRef, withReplace = true) + // TODO: `useMutableOrEmpty = true` is a workaround for KT-60324 until KT-60445 has been fixed. + +fieldList("bounds", typeRef, withReplace = true, useMutableOrEmpty = true) +annotations }