Skip to content

docs: structs key a Map by their whole value, and a compile error line may name its missing class - #111

Merged
heyJordanParker merged 3 commits into
masterfrom
docs/struct-keys-and-errata
Oct 12, 2026
Merged

heyJordanParker merged 3 commits into
masterfrom
docs/struct-keys-and-errata

Conversation

@heyJordanParker

@heyJordanParker heyJordanParker commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Problem

Section 10 shows a : string struct header that gives a struct a backing value so it can key a Map. Jordan ruled it out: any struct is a Map key by its whole value, with nothing declared. Section 10 also didn't state three of his other struct rulings:

  • a field with no initial value must be set at creation, and = null makes a nullable one optional
  • parse reads the main constructor's parameters, then every property an initializer may set
  • structs may be generic

Section 12 described Map keys by backing value, and its Username line said "keyed by username.value". Section 16's initializer-shorthand example built the harness Money, whose properties are get-only and set by its constructor.

The spec checker never let a missing-class error satisfy a compile error line. So a line whose rule is "this name doesn't exist", such as section 15's on OrderPayed, could never pass.

Nothing tested the checker's own rules. A rule broken in sharp/bin/spec would pass or fail examples silently, and the list would follow it. Decision 27 still recorded the : string header as its chosen key.

Solution

  • Section 10 states the whole-value Map key and four rules beside it:
    • a struct that holds a class instance at any depth can't key a Map
    • plain PHP sees a generated key text
    • JSON key text comes only from toString()
    • so Json.encode of a Map keyed by a struct without toString() is a compile error
  • The : string paragraph and its struct-backing-value example go.
  • Section 10 states the field-at-creation, parse-order and generic-struct rules. struct-changes gains one line that shows a missing field.
  • Sections 12 and 17 describe Map keys as int, string, a backed enum or a struct.
  • initializer-shorthand declares its own struct, Amount, in its own file block (app/Amount.sharp).
  • sharp/bin/spec lets a non-existent-class-like error satisfy a compile error line when that line writes the missing name outside a string. A missing name written on another line still fails as missing setup.
  • sharp/bin/spec --self-test checks the 17 examples of sharp/spec-self-test.md, one for each rule check_compile, check_run and the annotation reader apply. The <!-- expect <id> comment after each lists every problem it must give. sharp/bin/test --spec runs it before the examples, so a broken checker rule fails CI. 22 one-rule mutations of sharp/bin/spec each failed at least one example.
  • check() splits into measure(), which compiles and runs examples and returns their problems, and the list comparison. The self-test calls measure() too, so both use one path.
  • Decision 27 records the whole-value key and every rejected option with Jordan's reasons: the : string header, a fixed field name, a one-field limit and a toString() key.

struct-backing-value leaves sharp/baseline/spec. No entry joins it. listener-errors stays listed, because the pinned Mago can't parse an event yet.

The harness structs app/Username.sharp and app/OrderRow.sharp are not in this PR. The pinned Mago 625c278 can't parse struct, and sharp/bin/spec refuses to run when a harness file doesn't compile.

.github/workflows/
└── sharp.yml                    CHANGES counts sharp/spec-self-test.md as code
docs/
├── spec.md                      sections 10, 12, 16 and 17: struct rulings and the initializer-shorthand fix
├── architecture/
│   └── spec-examples.md         the missing-class exception, the self-test, a true parser rule example
└── decisions/
    ├── 026-collection-operations.md  a backed enum or a struct key arrives as its type
    └── 027-map-keys.md          whole-value struct keys, with every rejected option
sharp/
├── README.md                    the missing-class exception, and --spec runs the self-test first
├── bin/spec                     the missing-class exception, --self-test, measure()
├── bin/test                     --spec runs sharp/bin/spec --self-test
├── baseline/spec                struct-backing-value leaves
└── spec-self-test.md            new: 17 examples, one per checker rule, with the problems each must give

…e may name its missing class

Problem

Section 10 shows a `: string` struct header that gives a struct a backing value so it can key a Map. Jordan ruled it out: any struct is a Map key by its whole value, with nothing declared. Section 10 also didn't state three of his other struct rulings: a field with no initial value must be set at creation, parse reads initializer properties after the main constructor's parameters, and structs may be generic. Section 12 described Map keys by backing value, and its Username line said "keyed by username.value". Section 16's initializer-shorthand example built the harness Money, whose properties are get-only and set by its constructor.

The spec checker never let a missing-class error satisfy a `compile error` line. So a line whose rule is "this name doesn't exist", such as section 15's `on OrderPayed`, could never pass.

Solution

- Section 10 states the whole-value Map key, the rule that a struct holding a class instance at any depth can't key a Map, the generated key text plain PHP sees, and that JSON key text comes only from toString(). The `: string` paragraph and its struct-backing-value example go.
- Section 10 states the field-at-creation, parse-order and generic-struct rules. struct-changes gains one line that shows a missing field.
- Sections 12 and 17 describe Map keys as int, string, a backed enum or a struct.
- initializer-shorthand declares its own struct, Amount, in its own file block.
- sharp/bin/spec lets a non-existent-class-like error satisfy a `compile error` line when that line writes the missing name outside a string. A missing name written on another line still fails as missing setup.

struct-backing-value leaves sharp/baseline/spec. No entry joins it.

docs/
├── spec.md                      sections 10, 12, 16 and 17: struct rulings and the initializer-shorthand fix
└── architecture/
    └── spec-examples.md         the missing-class rule names its exception
sharp/
├── README.md                    the same exception, in one clause
├── bin/spec                     check_compile reads the missing name from the message and finds it on the line
└── baseline/spec                struct-backing-value leaves
…ole-value struct keys

Problem

sharp/bin/spec decides whether every spec example passes, and nothing tested its own rules. A rule broken in the checker would pass or fail examples silently, and the list would follow it. Decision 27 still recorded the `: string` struct header as its chosen key, which Jordan replaced with whole-value struct keys.

Solution

- `sharp/bin/spec --self-test` checks the examples of `sharp/spec-self-test.md`, one for each rule that check_compile, check_run and the annotation reader apply. The `<!-- expect <id>` comment after each lists every problem the check must report for it. A location there reads `line <n>`, counted from the example's first fence, and `…` matches any text.
- Each of the 17 examples fails when its rule is switched off. 22 one-rule mutations of sharp/bin/spec each failed at least one example.
- check() splits into measure(), which compiles and runs examples and returns their problems, and the list comparison. The self-test calls measure() on its own file, so both use one path.
- `sharp/bin/test --spec` runs the self-test before the examples. CHANGES counts the self-test file as code, so a pull request that changes only it still runs LINUX.
- Decision 27 records the whole-value key, the class-instance rule, JSON text from toString(), and the rejected `: string` header, fixed field name, one-field limit and toString() key, with Jordan's reasons. Decision 26's one sentence about key types follows it.
- The annotation doc's example of a parser rule message was `echo`, which the pinned Mago reports with the code `semantics`. It now names the untyped-parameter message, which carries the code `parse`.

.github/workflows/
└── sharp.yml                       CHANGES counts sharp/spec-self-test.md as code
docs/
├── architecture/spec-examples.md   the self-test, and a true parser rule example
└── decisions/
    ├── 026-collection-operations.md  a backed enum or a struct key arrives as its type
    └── 027-map-keys.md             whole-value struct keys, with every rejected option
sharp/
├── README.md                       --spec runs the self-test first
├── bin/spec                        --self-test, measure(), expectations(), like()
├── bin/test                        --spec runs sharp/bin/spec --self-test
└── spec-self-test.md               new: 17 examples, one per rule, with the problems each must report
Problem

Decision 27 said "team-lead ruled this from precedent … and it stays open to Jordan", which puts an internal Agent name and an open-review note into a repository record. Two of its other sentences recorded review steps rather than the decision. Decision 66 and the spec's "Undecided, in order" said the standard library is specified "by the team lead".

Solution

- Decision 27 writes the class-instance rule as every other chosen option is written: the rule, its precedent in Rust's HashMap and Swift's Dictionary, and section 19's Set for any later extension.
- Decision 27 keeps Jordan's rulings and quote, and drops the survey steps beside them.
- Decision 66 and the spec say the standard library is specified with the library itself.

docs/
├── spec.md                               "Undecided, in order" names no owner
└── decisions/
    ├── 027-map-keys.md                   the class-instance rule as rule and precedent
    └── 066-standard-library-ownership.md names no owner
@heyJordanParker
heyJordanParker merged commit 6629826 into master Oct 12, 2026
12 checks passed
heyJordanParker added a commit that referenced this pull request Oct 13, 2026
Master brings #111 (structs key a Map by their whole value, and
sharp/bin/spec checks its own rules) and #112 (the harness class Tenant
becomes Account, and the harness gains Receipts and Refunds). Neither
changes the engine.

The failing spec examples list keeps both sides' deletions:
- master removed §10 struct-backing-value, whose example #111 deleted
- the generics slice removed the four §9.1 constructor lines, which
  pass at the slice's pinned Mago

sharp/baseline/spec    both sides' passing examples removed
@heyJordanParker
heyJordanParker deleted the docs/struct-keys-and-errata branch November 3, 2026 22:08
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