Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions sjsonnet/src/sjsonnet/Val.scala
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ object Val {
extends Literal
with Expr.ObjBody {
private var asserting: Boolean = false
// Pre-computed flag: true if this object or any super has assert statements.
// Computed O(1) at construction from the super chain (super is already constructed).
// Allows skipping the triggerAllAsserts super-chain walk for assert-free objects.
private val hasAnyAsserts: Boolean =
triggerAsserts != null || (`super` != null && `super`.hasAnyAsserts)

def getSuper: Obj = `super`

Expand All @@ -384,9 +389,8 @@ object Val {
}

def triggerAllAsserts(brokenAssertionLogic: Boolean): Unit = {
// We need to avoid asserting the same object more than once to prevent
// infinite recursion
if (!asserting) {
// Short-circuit: no asserts in this object or any super
if (hasAnyAsserts && !asserting) {
asserting = true
triggerAllAsserts(this, `super`, brokenAssertionLogic)
}
Expand Down