Skip to content

fix: preserve outer self/$ for super[name] lookup (#829)#835

Closed
He-Pin wants to merge 2 commits intodatabricks:masterfrom
He-Pin:fix/issue-829-super-lookup
Closed

fix: preserve outer self/$ for super[name] lookup (#829)#835
He-Pin wants to merge 2 commits intodatabricks:masterfrom
He-Pin:fix/issue-829-super-lookup

Conversation

@He-Pin
Copy link
Copy Markdown
Contributor

@He-Pin He-Pin commented May 11, 2026

Motivation:
Issue #829 shows that sjsonnet fails to evaluate Grafana Mimir manifests because super[name] binds self/$ incorrectly during computed-key super lookups. That makes fields defined by later-applied mixins unreachable from inside the field returned by super[name], while other Jsonnet implementations evaluate the same manifests successfully.

Modification:

  • Pass the outer merged self through visitLookupSuper, matching the existing super.name behavior instead of rebinding to the parent object.
  • Add focused regression coverage for static-vs-dynamic super parity, chained mixins, object extension syntax, and a multi-file Grafana Mimir reproduction.
  • Add an in-source protective comment documenting why the explicit self argument must not be removed from sup.value(...).

Result:
sjsonnet now evaluates the Mimir-style overrideSuperIfExists(name, override) pattern correctly, and super[name] matches the semantics of super.name across the added regressions. The branch also leaves a guardrail comment in the evaluator so this subtle binding invariant is less likely to regress in future refactors.

References:

He-Pin added 2 commits May 10, 2026 02:25
Motivation:
visitLookupSuper was calling sup.value(key, pos) without passing self,
so the field retrieved through super[name] had its self/$ bound to the
parent object instead of the merged outer self. Fields defined in mixins
applied AFTER the parent therefore became unreachable from inside fields
retrieved via super[name] + override, breaking grafana/mimir's
overrideSuperIfExists helper:

  sjsonnet.Error: Field does not exist: ingest_storage_ingester_autoscaling_enabled
      at [overrideSuperIfExists].(mimir/rollout-operator.libsonnet:18:64)
      at [<root>].(mimir/memberlist.libsonnet:106:50)

Modification:
Pass scope.bindings(e.selfIdx) as the self argument, mirroring the
existing semantics of visitSelectSuper (super.name). Also use it as
the fallback when sup is null.

Result:
super[name] now agrees with super.name; fields retrieved through
computed-key super lookup see $ bound to the outermost merge result,
matching google/jsonnet, go-jsonnet, and jrsonnet. Adds two regression
tests under new_test_suite/: a focused parity/edge-case suite and a
multi-file end-to-end repro of the mimir failure.

References:
- databricks#829
…#829)

Motivation:
The fix in the previous commit is one line and easy to "clean up" by
removing the seemingly redundant `self` argument, which would silently
re-introduce issue databricks#829.

Modification:
Add a DO NOT CHANGE / WHY block in front of visitLookupSuper explaining
why `self` must be passed explicitly to `sup.value(...)` and pointing at
the cross-implementation contract with super.name.

Result:
Future readers (humans and AI alike) have an in-source warning explaining
the invariant before they touch this method.
@He-Pin He-Pin closed this May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant