Skip to content

Commit

Permalink
Fix KSValueArgumentImpl.defer()
Browse files Browse the repository at this point in the history
where its parent needs to be deferred as well.
  • Loading branch information
ting-yuan committed Aug 23, 2024
1 parent e5872fb commit 9c02ec9
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import org.jetbrains.kotlin.analysis.api.annotations.KtNamedAnnotationValue

class KSValueArgumentImpl private constructor(
private val namedAnnotationValue: KtNamedAnnotationValue,
override val parent: KSNode,
override val parent: KSNode?,
override val origin: Origin
) : KSValueArgument, Deferrable {
companion object : KSObjectCache<KtNamedAnnotationValue, KSValueArgumentImpl>() {
fun getCached(namedAnnotationValue: KtNamedAnnotationValue, parent: KSNode, origin: Origin) =
fun getCached(namedAnnotationValue: KtNamedAnnotationValue, parent: KSNode?, origin: Origin) =
cache.getOrPut(namedAnnotationValue) {
KSValueArgumentImpl(namedAnnotationValue, parent, origin)
}
Expand Down Expand Up @@ -56,5 +56,8 @@ class KSValueArgumentImpl private constructor(
return "${name?.asString() ?: ""}:$value"
}

override fun defer(): Restorable = Restorable { getCached(namedAnnotationValue, parent, origin) }
override fun defer(): Restorable {
val parent = if (parent is Deferrable) parent.defer() else null
return Restorable { getCached(namedAnnotationValue, parent?.restore(), origin) }
}
}

0 comments on commit 9c02ec9

Please sign in to comment.