Repository navigation
docs: structs key a Map by their whole value, and a compile error line may name its missing class - #111
Merged
Conversation
…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
enabled auto-merge
October 12, 2026 19:42
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Section 10 shows a
: stringstruct header that gives a struct a backing value so it can key aMap. Jordan ruled it out: any struct is aMapkey by its whole value, with nothing declared. Section 10 also didn't state three of his other struct rulings:= nullmakes a nullable one optionalparsereads the main constructor's parameters, then every property an initializer may setSection 12 described
Mapkeys by backing value, and itsUsernameline said "keyed by username.value". Section 16'sinitializer-shorthandexample built the harnessMoney, whose properties are get-only and set by its constructor.The spec checker never let a missing-class error satisfy a
compile errorline. So a line whose rule is "this name doesn't exist", such as section 15'son OrderPayed, could never pass.Nothing tested the checker's own rules. A rule broken in
sharp/bin/specwould pass or fail examples silently, and the list would follow it. Decision 27 still recorded the: stringheader as its chosen key.Solution
Mapkey and four rules beside it:MaptoString()Json.encodeof aMapkeyed by a struct withouttoString()is a compile error: stringparagraph and itsstruct-backing-valueexample go.struct-changesgains one line that shows a missing field.Mapkeys asint,string, a backed enum or a struct.initializer-shorthanddeclares its own struct,Amount, in its own file block (app/Amount.sharp).sharp/bin/speclets anon-existent-class-likeerror satisfy acompile errorline 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-testchecks the 17 examples ofsharp/spec-self-test.md, one for each rulecheck_compile,check_runand the annotation reader apply. The<!-- expect <id>comment after each lists every problem it must give.sharp/bin/test --specruns it before the examples, so a broken checker rule fails CI. 22 one-rule mutations ofsharp/bin/speceach failed at least one example.check()splits intomeasure(), which compiles and runs examples and returns their problems, and the list comparison. The self-test callsmeasure()too, so both use one path.: stringheader, a fixed field name, a one-field limit and atoString()key.struct-backing-valueleavessharp/baseline/spec. No entry joins it.listener-errorsstays listed, because the pinned Mago can't parse an event yet.The harness structs
app/Username.sharpandapp/OrderRow.sharpare not in this PR. The pinned Mago 625c278 can't parsestruct, andsharp/bin/specrefuses to run when a harness file doesn't compile.