Repository navigation
docs: the spec states Jordan's specimen rulings, no type nests, and 12 examples lose their bugs - #106
Merged
Merged
Conversation
… lose their bugs Problem - The spec didn't say what `new Order.Paid(…)` means when `Order` has both a nested type and a named constructor named `Paid`, whether `extern event` takes `uses`, whether a class may nest a type with its own name, or how a Lean structure rule is written. - Twelve examples failed because the example itself had a bug, not because a feature was missing, so a developer copying them got code that doesn't compile. Solution - §15: `new Order.Paid(…)` creates the nested type when `Order` declares one, and calls the named constructor `Paid` otherwise. Declaring both is a compile error. A class can't nest a type with its own name (C# CS0542). `extern event JobFailed uses Database;` states the class's effects, and `extern event JobFailed;` stays pure. - §28.1: a structure rule is a Lean definition with `@[rule]`, as in `@[rule] def importsOnly : Rule := .importsOnly [Billing.Money, Shared]`. - The twelve examples carry their fixes, each rule unchanged. lifted-equality, is-not-scope, property-narrowing and any-checks now pass and leave sharp/baseline/spec. The four new §15 examples join it until events and named constructors are built. docs/ └── spec.md # §15 rulings and 4 examples, §28.1 @[rule] bullet, 12 example fixes sharp/ └── baseline/spec # -4 passing examples, +4 new §15 examples
Problem
- The spec nested events and their interface inside the class that raises
them, as `Order.Paid` and `Order.Event`. Jordan ruled that nothing nests, so
a reader finds every type by its namespace and file, as in PHP.
- The spec didn't say whether a PHP keyword PHP# doesn't use can name a
local, whether a change through an index sticks, whether a body may go
without braces, whether a subclass constructor may skip `: super(…)`,
whether `: super(…)` may read `this`, or whether a named constructor may
set a get-only property again.
Solution
- §15: every event and event interface is its own file at file level, as
`app/OrderPaid.sharp` declares `OrderPaid`. Listeners, `emit` and §24's and
§29's examples use the file-level names. `new Order.Paid(…)` always calls the
named constructor, and a type in the namespace `App.Order` beside the class
`App.Order` is §23's compile error. The nested-type-named-like-its-class
rule is gone, because nothing nests.
- §2: `empty`, `list` and `print` can name a local, and PHP#'s keywords stay
reserved.
- §12: a `List` index is a place, and a change through a `Map` index is
refused: "a Map read is a copy: read it, change it, and store it back".
- §17: every `if`, `else`, `while`, `do` and `for` body is in braces. The two
braceless guards in §9 and §14.2 gained them.
- §9.1: a subclass constructor always writes `: super(…)`, `this` is refused
in `: super(…)` and `: this(…)`, and a get-only property is set once, so a
named constructor sets again only a `{ get; init; }` property.
docs/
└── spec.md # §2, §9.1, §12, §15, §17 rulings; §9, §14.2 braces; §24, §29 file-level events
sharp/
└── baseline/spec # the 7 new examples join, and §15's entries follow its renamed examples
…ng 1 in one sentence
Problem
- §19 operators declared a get-only `id` that nothing set, so its run threw
"Typed property App\DatabaseEntity::$id must not be accessed before
initialization".
- The §28.1 `@[rule]` line writes bare names, and Mago takes quoted full
names. Jordan hasn't settled which form wins.
- §15 showed ruling 1 with an example of §23's existing error, and the
answer needs one sentence and no new error.
Solution
- §19 operators declares `public int id { get; set; } = 1;`, as the shared
`DatabaseEntity` does, so the example runs and leaves the list.
- §28.1's text is master's again.
- §15 says in one sentence that `new Order.Paid(…)` always calls the named
constructor, and that §23 already refuses a type `App.Order.Paid` beside the
class `App.Order`. The event-beside-class example is gone.
docs/
└── spec.md # §15 ruling 1 sentence, §19 operators id, §28.1 as master
sharp/
└── baseline/spec # operators leaves
…ype's file
Problem
- Jordan ruled that every type is declared in its own file in a namespace,
as Composer's PSR-4 autoloader loads one class per file. The spec said it
only in §15, and 18 examples outside §15 showed two or more types in one
block, so a reader copied files the rule forbids.
- §12 said `points[0].x = 5` sets `x` on the stored point. No type makes that
true: a struct never changes, and a class instance in a List is shared.
- §19 operators set `id` with `{ get; set; } = 1`, which changes the rule
Jordan's fix shows.
Solution
- §27 states the rule once: a `.sharp` file declares one type, named like the
file, and a second type is a compile error. §15 points to it.
- Every example that showed several types shows each type in its own block,
with its path and namespace, as §15's event-declarations does. Statements
stay in a block of their own.
- §12's index rule keeps `grid[0].add(5)` and drops `points[0].x = 5`.
- §19 operators declares `public int id { get; }`, set by
`DatabaseEntity`'s constructor. It stays on the list until the shared
`Order` calls `: super(…)`, which the pinned Mago doesn't parse yet.
docs/
└── spec.md # §27 one-type rule; 18 examples split into files; §12 prose; §19 operators
sharp/
└── baseline/spec # operators and one-type-per-file join
Problem - §9.1 says there is no overloading by argument types, yet super-call gave `Invoice` two constructors and set-once gave `Money` two `Money.zero` named constructors. A reader learned that a second one is fine, and once the checker refuses duplicates, the error line could pass on that error instead of the rule it shows. Solution - super-call refuses the missing `: super()` in a second subclass, `app/CreditNote.sharp`, so `Invoice` keeps one constructor. - set-once names the refused named constructor `Money.free`. - Neither example needs `alone` now, because every line is valid beside the others except the one error it marks. docs/ └── spec.md # §9.1 super-call and set-once
heyJordanParker
added a commit
that referenced
this pull request
Oct 12, 2026
Problem: master moved 8 commits past the branch: the #106 spec rulings and the #107 merge. The branch's sharp/bin/build and sharp/bin/census already match master, but its docs/spec.md and sharp/baseline/spec do not. Solution: merge origin/master with no rebase. docs/spec.md merged cleanly. sharp/baseline/spec conflicted on the two examples master added as failing, §12 index-changes and §12 index-rules, which the branch's baseline lacked. The merge keeps both lines. The re-pin's spec run decides whether they still fail. docs/spec.md master's rulings, merged without conflict sharp/baseline/spec master's two new §12 lines kept
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
Order.PaidandOrder.Event, and many examples showed several types in one block. Jordan ruled that every type is declared in its own file in a namespace.new Order.Paid(…)means whenOrderhas a named constructorPaid,extern eventtakesuses,: super(…),: super(…)may readthis,Solution
Jordan's rulings, written into the sections they belong to:
.sharpfile declares one type, named like the file, as Composer's PSR-4 autoloader loads one class per file. A second type in a file is a compile error. Exampleone-type-per-file.event-declarationsshowsapp/OrderEvent.sharp,app/OrderPaid.sharp,app/OrderRefunded.sharp,app/Order.sharpandapp/Receipts.sharp, each with its namespace. "the way C# nests types" is gone.emit-forms,listeners,listener-errors, §24'snaming-casesand §29'semit-effectuse the file-level names.new Order.Paid(…): one sentence says it always callsOrder's named constructorPaid, because.in code is always member access, and that §23 already refuses a typeApp.Order.Paidbeside the classApp.Order. It adds no new error.extern event JobFailed uses Database;: it states the class's effects, as §29'sextern … usesdoes.extern event JobFailed;stays an event and pure. Exampleextern-event-effects.@[rule]example writes bare names, and Mago takes quoted full names, so §28.1 stays as master has it until Jordan answers.empty,listorprint, can name a local. Every keyword PHP# uses stays reserved. Examplekeyword-names.Listindex is a place, as a RustVecindex and a Go slice index are, sogrid[0].add(5)changes the stored list. A change through aMapindex is refused: "a Map read is a copy: read it, change it, and store it back". Exampleindex-changes.if,else,while,doandforis written in braces, as in Go, Rust, Swift and PSR-12. Examplebraces.: super(…): a subclass constructor always calls its parent's with: super(…), even when the parent takes no arguments, as Kotlin always writes: Document(). Examplesuper-call.thisin a constructor call:thisin the arguments of: super(…)or: this(…)is refused: "thisis not available before the constructor runs: pass a parameter instead." Exampleconstructor-call-this.{ get; init; }, as §6.1 allows. Exampleset-once, with bothMoney.zerolines. The old bullet "A named constructor … can set get-only properties" is replaced.Examples that now show each type's file
Each type is its own block with its path and namespace, and the statements that use them stay in a block of their own:
super-call:Document.sharp,Invoice.sharpstruct-changes:Point.sharp,Size.sharpenum-map-keys:Status.sharp,OrderStats.sharpreadonly-fields:Invoice.sharp,Bill.sharp,Quote.sharp,Receipt.sharpevent-declarations:OrderEvent.sharp,OrderPaid.sharp,OrderRefunded.sharp,Order.sharp,Receipts.sharpoperators:DatabaseEntity.sharp,Money.sharpsealed-interfaces:Interaction.sharp,PopupInteraction.sharpvirtual-methods:DatabaseEntity.sharp,Page.sharpoverride-parameter-names:Image.sharp,Thumbnail.sharpinterface-defaults:HasDesign.sharp,Page.sharpplain-php-traits:Order.sharp,Draft.sharpnaming-cases:Billing/Status.sharp,Billing/Invoice.sharp,Billing/InvoicePaid.sharpclass-values:Element.sharp,FormBuilder.sharprequired-constructors:Order.sharp,Invoice.sharppure-interface:Formatter.sharp,Visitor.sharp,FileFormatter.sharpenvironment:Deploy.sharp,CheckoutController.sharpextern-implementations:AudienceSync.sharp,StripeGateway.sharp,MailchimpSync.sharp. The imports that were hidden setup are now in the files that use them.emit-effect:OrderPaid.sharp,Checkout.sharp,StoreCheckout.sharp. The event that was hidden setup is now its own file.error-interface: the standard library'sError, andPaymentError.sharpBraceless bodies that gained braces
parameter-members:if (!tenant.active) throw new InactiveTenant(tenant);becameif (!tenant.active) { throw new InactiveTenant(tenant); }.lambdas:if (line.free) return Money.zero(currency);becameif (line.free) { return Money.zero(currency); }.No other
if,else,while,doorforbody indocs/spec.mdorREADME.mdwas missing braces.The twelve example fixes
Each fix changes the example only, never the rule it shows. These fixes needed more than the line named:
DatabaseEntitydeclares Jordan'spublic int id { get; }, set by its constructor,public DatabaseEntity(int id) { this.id = id; }, and the setup createsnew Order(1). It stays on the list: the sharedOrderhas no constructor that calls: super(id), so the run throws "Typed property App\DatabaseEntity::$id must not be accessed before initialization". It passes once: super(…)reaches the pinned Mago and the sharedOrdercalls it.total == Money.zero, had the same bug, so it also becameMoney.zero("USD"). Its annotation became// false: total is a Money, …, because a bare comparison whose annotation names no value is refused as "This statement has no effect".Log.infois Laravel's facade, so the marker's hidden setup importsIlluminate.Support.Facades.Log, as §25'stypeof-valuesdoes.this.pricesandthis.customersneed declared fields. They are hidden setup lines,private Map<string, int> prices = [:];andprivate Map<int, Customer> customers = [:];, as §14.4'sneedless-null-checksdeclares its field.public ImportScreen(private ProgressBar progress, private Importer importer) { }(§9). The marker's shape becamemembers, and its hidden setup declaresProgressBarandImporter, which the harness lacks.TextExtensions.sharpis inApp.Shared.Text, so it importsIlluminate.Support.Str, as §14.3 does. Thestring titlesetup moved to the second block.The list
sharp/baseline/specgoes from 96 to 100 entries.These four leave, because they now pass:
These eight join. Each is a new example for a ruling that isn't built yet:
const match = 1;.: super()is a parse error, and a constructor without it compiles.grid[0].add(5)is refused with "This method changes the collection, which has no place to be written back to."extern eventis a parse error.These fixed examples stay listed, because a feature they use isn't built yet:
internal setis a parse error.?? returnand?? continueare parse errors.eventdeclarations are parse errors.Events.on<RowImported>(…)is read as a chained comparison. The harness also has noApp.Imports.RowImported.Orderdoesn't call: super(id), as above.extension(string value)is a parse error.Files