Skip to content

feat: compose arrays on inheritance with the $super splice marker - #97

Closed
dakusui wants to merge 1 commit into
mainfrom
feat/super-splice-91
Closed

dakusui wants to merge 1 commit into
mainfrom
feat/super-splice-91

Conversation

@dakusui

@dakusui dakusui commented Sep 2, 2026

Copy link
Copy Markdown
Owner

Phase 1 of tasks.md for #91, following the planning merged in #96. Implements the $super splice marker and the rules around it. $super* pairing is phase 2 — see the intermediate state note below.

The change in one line

Arrays were replaced on inheritance not by decision but by omission: MergeObjects recursed when both sides were objects and let everything else fall through to child-replaces. This adds composition at that same seam.

What landed

  • internal/markers.go classifies a string in direct array element position. A defined marker is a marker; $super followed by an identifier character is a different word and stays data ($supervisor); $super followed by anything else is an undefined spelling in the reserved namespace and is an error — which is what keeps $super[1:] and $super? available to gain meaning later.
  • MergeObjects composes a marked array against the array it inherits, splicing the inherited elements at the marker's position. It now returns an error, so mergeObjects and resolveInheritances thread one.
  • Splicing builds a fresh slice. The node pool shares backing arrays between every document that inherits a file, so appending into one would corrupt them all.
  • Inherited elements are copied verbatim, markers included, so two splice deltas compose into a third that is still pending — the property the associativity requirement rests on.
  • A marked array carries while the inherited array is absent, which is what lets an $includes fragment contribute to a document it knows nothing about.
  • Grounding walks the top-level object after composition and reports any marker that never resolved, including one nested where nothing could ever bind it. It runs before value-side evaluation, so an eval:-produced string is never classified as a marker.

Diagnostics

Task 1.1 settled the wording before any negative case was written, and recorded it in design.md. Every message shares the prefix array composition, so the family is greppable and the autotest cases match a stable string rather than each inventing their own.

ERROR: unresolved array composition marker: "$super": at '.m': in input.json

Tests

18 autotest cases — 11 under inheritance/array-composition, 7 under negative/array-composition — plus unit tests for marker classification.

go test ./...          ok (all packages)
tools/bin/autotest     No test failed (total=173; passed=173; skipped=0)

No regressions; the pre-existing inheritance cases pass unchanged, and unmarked-replaces and nested-in-replaced-array pin the unchanged default explicitly.

Intermediate state, deliberate

Between this PR and phase 2, $super* is reported as an unresolved marker rather than pairing. It errors instead of silently mis-composing, which is the safe half of the eventual behaviour, but the spec delta is not satisfied for that marker until phase 2 lands.

One consequence worth flagging for review: negative/array-composition/nested-in-queue-element passes today for the wrong reason. It asserts that {"m": ["$super*", ["$super", 5]]} is rejected as an unresolved marker, and it is — but right now the outer $super* is the unresolved one. After phase 2, pairing will take the queue element whole and the inner $super will be the unresolved one, at path .m[0]. Same verdict, different cause. I left the assertion loose rather than pinning a path that is about to change.

Notes

tasks.md is shared state, so phase 2 has to follow this rather than run alongside. Tasks 1.1–1.10 are ticked.

Phase 1 of tasks.md. Implements the splice marker and the rules that
surround it; $super* pairing is phase 2.

Arrays were replaced on inheritance not by decision but by omission:
MergeObjects recursed when both sides were objects and let everything
else fall through to child-replaces. This adds composition at that same
seam.

- internal/markers.go classifies a string in direct array element
  position. A defined marker is a marker; $super followed by an
  identifier character is a different word and stays data; $super
  followed by anything else is an undefined spelling in the reserved
  namespace and is an error, which is what keeps $super[1:] available to
  gain meaning later.
- MergeObjects composes a marked array against the array it inherits,
  splicing the inherited elements at the marker's position. It now
  returns an error, so mergeObjects and resolveInheritances thread one.
- Splicing builds a fresh slice. The node pool shares backing arrays
  between every document inheriting a file, so appending into one would
  corrupt them all.
- Inherited elements are copied verbatim, markers included, so two
  splice deltas compose into a third that is still pending.
- A marked array carries while the inherited array is absent, which is
  what lets an $includes fragment contribute to a document it knows
  nothing about.
- Grounding walks the top-level object after composition and reports any
  marker that never resolved -- including one nested where nothing could
  ever bind it. It runs before value-side evaluation, so an eval:
  produced string is never classified as a marker.

18 autotest cases: 11 under inheritance/array-composition, 7 under
negative/array-composition. Unit tests cover marker classification.
Full suite 173/173, no regressions.

Refs #91

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@dakusui

dakusui commented Sep 2, 2026

Copy link
Copy Markdown
Owner Author

Superseded by a stack, at the maintainer's request — this PR carried the engine, the tests, and the planning artifacts as one commit.

PR Contents Base
1 #98 engine — 5 files under internal/ main
2 #99 autotest — 71 case files #98
3 #100 OpenSpec — design.md, tasks.md #99

Nothing changed in the split: the tip of the stack is byte-identical to the commit on this branch, verified with git diff. Phase 1 touches no shipped documentation, so there is no fourth part; the documentation tasks are 3.1–3.5, in phase 3.

Closing without merging. The branch feat/super-splice-91 is left in place for now and can be deleted once the stack lands.

@dakusui dakusui closed this Sep 2, 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