Skip to content

feat: every rule of section 11, generics, compiles, refuses or runs as the spec says - #142

Merged
heyJordanParker merged 28 commits into
masterfrom
feat/generics-rest
Oct 16, 2026
Merged

heyJordanParker merged 28 commits into
masterfrom
feat/generics-rest

Conversation

@heyJordanParker

@heyJordanParker heyJordanParker commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Completes: §11

Problem

Section 11 (generics) had three spec examples in sharp/baseline/spec: generic-method-inference, raw-generic-objects and type-parameter-bounds. A generic class's static with accessors, and its static whose initial value runs as code, were "not supported yet". A value of a method's type parameter entered from plain PHP without its bound checked. A default body whose bound names its interface's type parameter was refused falsely. The declared type did not reach a generic call through a match arm, a lambda's result or an outer generic call. A bound could not name another type parameter, and a plain PHP @template class compiled without its type arguments. A generic struct was "not supported yet".

Solution

Every rule of section 11 and 11.1 now compiles, refuses or runs as the spec annotates, in the checker, the bridge and the engine. The design, each rule's state on master and what this branch builds for it are in docs/architecture/slices/11-generics-rest.md.

  • Each type argument's statics run their initial values and accessors. A generic class with static fields has one hidden static method, #entry, which every access calls with its type arguments. It returns that type argument's entry of the statics store by reference, and the call that adds the entry runs each initial value that runs as code, once, as C# runs a closed type's static initializer on its first use. \Sharp\Internal\statics takes ?bool &$created = null for it. A static's name#get and name#set take the class's type arguments, keep their storage in the entry, and a static lazy value is kept per type argument. Engine: type_arguments_call_statics.phpt, type_arguments_preload.phpt.
  • Statics reached through a generic subclass or a type parameter take the right type arguments. Wrapped<TX> : Counter<List<TX>> reaches Counter<List<Shelf>>'s statics for Wrapped<Shelf>, and TCounter.count with TCounter : Counter<Order> reaches its bound's.
  • A static whose initial value threw throws PHP's error until a write sets it. The throw reaches the code that first used the statics, and nothing runs again. A later read, compound assignment, ++ or -- of the static it left unset throws "Typed static property App\Counter::$made must not be accessed before initialization", as in a class that isn't generic. It had read as OutOfRangeException, and += had warned and written. A read checks its entry only when the value it reads is not there or null, 5.3 instructions a read. An update checks inside its index, 138 instructions.
  • A static's initial value that reads another static runs as code, in any class, and one that reads a constant or an enum case stays PHP's default.
  • A property names its class's type parameters. A generic class's property initial value and accessor bodies, static or not, write T in a type, as Holder<T>.total, where they got "Cannot find type T."
  • The declared type reaches a generic call through each match arm, into a lambda's result from an expression body and from return, into a lambda that is a generic call's argument, and through an outer generic call's parameter, so List<Order> f = this.keep(this.get("k")); compiles (question 1). A lambda for Function<void()> fixes no type argument.
  • An argument fixes a type argument PHP# writes. Box<int> b = Factory.of(5); compiles, and Collection.make([new Order()]) goes into Collection<int, Order>, where both had compared a literal 5 or a list's non-negative-int key with int. A scalar widens, an enum case is its enum, and an array is its List, Map or Set.
  • A bound may name another type parameter, as <TSub : T>, alone, never beside &, and never leading back to itself (question 2). A value of TSub goes where a T goes. A static method's bound that names the class's type parameter is checked from plain PHP. Engine: type_arguments_entry_unresolved.phpt.
  • A PHP# type and new name a plain PHP generic class's type arguments (question 3): Shelf shelf and new Shelf() are "Shelf needs its type argument.", with the help "Write a type for its type parameter: Shelf<TItem>." A type test and a catch name the class alone, and a type parameter with a default needs none.
  • A struct can be generic, as public struct Pair<TFirst, TSecond>. == compares a property of a type parameter as its type argument does, Map<Pair<int, string>, int> keys by value, and Pair<int, string>.parse and tryParse check each field against the type arguments, a nested generic struct's too. A field of a type parameter reads only as its input holds it, so a type argument parse would build first, a struct, a class, a Map, a Set or an enum case, is a compile error that says so. Each type argument has its own statics. Engine: structs.phpt, type_arguments_preload.phpt.
  • A value of a method's own type parameter enters within its bound. From plain PHP, boxed<TBox : Box<T>> on a Pages<Order> refuses a raw Box and a Box<Customer>, and still takes a Box<Order>.
  • A default body's bound reads the type argument the class gives. OrderShelf : Shelved<Order> takes kind<TBox : Query<T>> as TBox : Query<Order>, and the engine spells a default body's bounds in the interface's scope. Engine: inheritance_defaults.phpt.
  • A PHP# method with neither parameters nor a return type got no ZEND_SHARP_RECV_TYPE_ARGS, so it read type arguments its frame never got. #entry is the first such method, and zend_compile_params now emits the receive on that path too.

The cost of #entry's frame

Instructions retired per access, release builds of both heads, 10,000,000 passes, median of 3. Per access is the loop's count less the same loop without the static, divided by the passes. Master is 24bd9909cf with its own mago.

                     read: master  branch  ratio    write: master  branch  ratio
interpreter                 465.3   864.4   1.86            460.9   862.3   1.87
opcache                     519.1   926.2   1.78            517.2   924.2   1.79
tracing JIT                 452.0   832.2   1.84            502.0   878.2   1.75

The first shape read at 2.03 times master's in the interpreter. #entry now declares no return type, so PHP checks none on each access, and a class whose initial values are all constant returns the store's entry with no reference bind.

A class with an initial value that runs as code keeps that bind. Interpreter, one class holding count = 1 and made = Counter<T>.count + 1, against master's 464.9 the same hour:

                                  per access   ratio
read of count                         1072.5    2.31
read of made, checked                 1077.8    2.32
count += 1                            1129.4
made += 1, checked                    1267.4

Where the build differs from the approved note

  • The entry check of a method type parameter is in the bridge, not the engine's unresolved #i. Types::checked_text writes such a parameter's check as its bound, as it already did for a bound that names a trait. The engine is unchanged for it.
  • A default body's bound is fixed in the codex, not in report_signature_compatibility_issue. reparent_types gives a default body's own bounds the header's type arguments, and inferred_type_replacer replaces inside a reference the populator has not resolved yet.

Changes to the spec text

  • Lines 749 and 751 state question 3, and the new example plain-php-generic-types shows it. Line 748 says new names them too. Line 750 states question 1, and generic-method-inference gains the row cache.keep(cache.get("orders")). Line 751 says what type an argument fixes. Line 809 states question 2, with three rows in type-parameter-bounds.
  • Line 252 says what a throw in a static's initial value leaves.
  • generic-method-inference's hidden setup gains namespace App.Inference; and import App.Order;, since App.Cache met the harness folder app/Cache/. property-references' hidden setup creates Query<Order>.

Harness changes

  • sharp/harness/app/Query.sharp declares Query<T>, which type-parameter-bounds writes as Query<TItem>.
  • Zend/tests/sharp/IndexRead.sharp writes Map<string, SplFixedArray<int>> and new SplFixedArray<int>(3), question 3's sweep.
  • sharp/mago/tests/external_analyzer_refinement.rs: the PHP# caller returned a bare Box, which a refinement makes generic with T : Spec. Its result is Box<Special> in one run and Box<Spec> in the other, and Box is invariant, so it now returns Any. The test checks the compiled key and its inputs, which the result type does not change.

Names this PR adds

  • #entry, the hidden static method of a generic class's statics, and $created, \Sharp\Internal\statics's third parameter, as the note's decision 6 picked.
  • $statics#N, the hidden variable an update of a static that a throw can leave unset binds to its entry.
  • MetadataFlags::RUNTIME_INITIAL_VALUE, which the codex gives a PHP# static whose initial value runs as code.
  • sharp_type_scope is exported from ext/sharp/sharp.c and declared in php_sharp.h, for ZEND_SHARP_RECV_TYPE_ARGS.
  • HintPlace, with TypeTest and Declaration, says where the analyzer checks a hint. report_missing_type_arguments is the one check of a type's missing type arguments, for a type and for new.

Verification

  • Every engine test, 293 of 293, passes without opcache, with the file cache primed and used, twice per process with shared memory, with each of the 16 optimizer passes alone, and under the tracing and function JITs. type_arguments_preload.phpt runs a preloaded generic class's initial values and a preloaded generic struct.
  • structs, table_keys, struct_keys, parse, type_arguments_call_statics and type_arguments_preload pass 50 repeats each with USE_ZEND_ALLOC=0 MallocScribble=1 and opcache.
  • sharp/bin/spec: "Checked 202 examples, ignored 1, and 14 fail", none in section 11, each with its entry in sharp/baseline/spec. --self-test: 20 of 20.
  • mago: cargo test --workspace --locked --no-fail-fast with MAGO_REQUIRE_PHP_SDK_TESTS=1 passes all 180 test binaries, cargo fmt --all --check is clean, and clippy --workspace --all-targets -D warnings is clean.
  • A plain PHP project's analysis is unchanged: master's mago and this branch's report the same 1,417 issues over illuminate/container 12 and its dependencies.

Problem

Section 11 has three listed examples, two refused forms of generic
statics, and rules no note had probed line by line. Nobody had shown
which rules hold on master and which do not.

Solution

The note probes every section 11 and 11.1 rule on master 5576962,
with a release mago and the engine, and gives each its state and
mechanism. Four gaps remain: generic statics, a method bound checked at
entry, an inherited default body's bound, and the declared type through
a match arm and a lambda. The three examples fail on their setup only.

docs/architecture/slices/11-generics-rest.md   new
…nd an outer call

Problem

A PHP# generic call takes the type arguments nothing else fixes from the
declared type its result goes into. Four places lost that declared type,
so the call was refused with "Nothing fixes the type argument `T`":

- each arm of a `match`
- a lambda's expression body, written for a function type
- a `return` inside a block lambda, written for a function type
- an argument of an outer generic call, as in
  `List<Order> orders = this.keep(cache.get("nested"));`

The outer call also lost its own declared type once an argument took
one, because both share the one expected-type slot.

Solution

- A PHP# `match` gives its declared type to the PHP `match` it runs as,
  and that gives it to each arm.
- A lambda with no written result type takes the result type of the
  function type it goes into, for its expression body and its `return`s.
- A generic call reads its declared type before its arguments. The type
  arguments that declared type fixes give an argument its parameter's
  type when no argument has fixed it yet. An argument still wins.

sharp/mago/crates/analyzer/
├── src/artifacts.rs                     lambda_result
├── src/expression/match.rs              arms take the declared type
├── src/expression/mod.rs                a PHP# match passes it on
├── src/invocation/analyzer.rs           declared type before arguments
├── src/statement/function_like/mod.rs   a lambda's result type
├── src/statement/return.rs              a lambda's return
└── tests/sharp.rs                       rows for each form
Problem

Two section 11 examples failed for their setups, not for PHP#:

- type-parameter-bounds writes `Query<TItem>`, and the harness `Query`
  took no type parameter.
- generic-method-inference declares `Cache` in `App`, where the harness
  already has the `App.Cache` namespace.

Solution

- The harness `Query` is `Query<T>`, and the typed property references
  example writes `Query<Order>`.
- generic-method-inference declares its `Cache` in `App.Inference`.
- Both examples leave sharp/baseline/spec.

sharp/
├── harness/app/Query.sharp       Query<T>
└── baseline/spec/§11/            two entries leave
docs/spec.md                      two setups
Problem

Section 11 says a type names the type arguments of a generic class, and
a plain PHP `@template` class takes them in PHP# code. A bare
`Shelf shelf` still compiled when `Shelf` was a plain PHP class: only a
PHP# class was refused. The nested call `keep(cache.get("orders"))`,
which now compiles, had no spec line.

Solution

- A bare plain PHP generic class in a PHP# type is the error a bare
  PHP# generic class gets: "`Shelf` needs its type argument." Its help
  now names the type parameters to write, for both: "Write a type for
  its type parameter: `Shelf<TItem>`."
- A type parameter with a default may be left out.
- A type test and a `catch` test a plain PHP class alone, since its
  objects carry no type arguments: `x is Collection` still compiles.
- `new` and a static member of a plain PHP class are unchanged.
- The spec states both rules, with the example plain-php-generic-types
  and a nested call in generic-method-inference.
- The sweep found one bare type, `Map<string, SplFixedArray>` in
  Zend/tests/sharp/IndexRead.sharp, and one in an analyzer test.

sharp/mago/crates/analyzer/src/
├── expression/instantiation.rs          report_unnamed_type_arguments
├── statement/function_like/mod.rs       a type refuses both kinds
├── statement/mod.rs                     `tested` for type tests
├── expression/mod.rs, statement/try.rs  type tests pass `tested`
└── invocation/template_result.rs        a call's type argument is a type
docs/spec.md                             the two rules and examples
Zend/tests/sharp/IndexRead.sharp         SplFixedArray<int>
Problem

`public void add<TSub : T>(TSub item)` was refused: "A bound is
`Object`, a class or an interface". C#'s `where TSub : T`, Java's and
TypeScript's `<U extends T>` all allow it. Once allowed, the analyzer
refused a `TSub` where a `T` goes, and `<T : T>` or
`<TA : TB, TB : TA>` compiled with no error.

Solution

- A bound may be another type parameter, alone, as in Java. Joined with
  `&` it gets "A type parameter is a bound alone, as in `<TSub : T>`".
- A bound that leads back to its own type parameter, directly or
  through others in its list, is "A type parameter can't bound itself",
  as C# refuses a circular constraint (CS0454).
- In PHP# a type parameter holds a type parameter whose bound names it,
  through a chain too, so `TSub` goes where `T` goes.
- The spec states the rule in the bounds example.

sharp/mago/crates/
├── semantics/src/internal/checker/sharp.rs   the bound and its cycle
├── semantics/tests/sharp.rs                  rows for both
├── codex/src/ttype/comparator/atomic_comparator.rs   TSub in T
└── analyzer/tests/sharp.rs                   values and type arguments
docs/spec.md                                  the rule and its example
Problem

An interface's default body whose own type parameter is bounded by the
interface's, as `int kind<TBox : Query<T>>(TBox box) => 1;` in
`Shelved<T>`, broke in three places:

- The checker refused every class that took the body: "`OrderShelf.kind`
  must keep the bound `Query<Order>` of `Shelved.kind`". The body's copy
  in the interface's Defaults trait kept the interface's `T`, because
  the scanner moved its parameter and return types onto the trait's
  type parameters but not its bounds, and the replacer never entered a
  reference such as `Query<T>` that the populator has not resolved yet.
- A call on a `Shelf<Line>` was not checked against `Query<Line>`.
- From plain PHP, the engine spelled the bound with the class's own
  type arguments, so `T` came from the wrong position in
  `Ranked<int, string> : Keyed<string>`, and `Coded : Keyed<int>`, which
  has none, threw "Cannot read the type arguments of the class a lambda
  is written in from an object of another class".

Solution

- The scanner moves a default body's type parameter bounds onto the
  trait's type parameters too.
- The replacer replaces type parameters inside an unresolved reference.
- ZEND_SHARP_RECV_TYPE_ARGS spells the bounds in sharp_type_scope of
  its function, as sharp_type_check_arguments already does, so a
  method a class took from a trait counts the interface's type
  parameters. sharp_type_scope is declared in php_sharp.h.

sharp/mago/crates/
├── codex/src/scanner/mod.rs                          bounds move
├── codex/src/ttype/template/inferred_type_replacer.rs   references
└── analyzer/tests/sharp.rs                           the checker rows
Zend/
├── zend_vm_def.h, zend_vm_execute.h                  the scope
└── tests/sharp/Inheritance.sharp, inheritance_defaults.phpt
ext/sharp/sharp.c, php_sharp.h                        sharp_type_scope
…s bound

Problem

A call from plain PHP gives a PHP# method's own type parameters no type
arguments, so the entry check matched them against any value. A raw
`new Box()` entered `boxed<TBox : Box<Order>>(TBox box)`, and a
`Customer` entered `Rack<Order>.add<TSub : TItem>(TSub item)`. The body
then read a value its types never allow.

Solution

The bridge checks a parameter whose type is a method's own type
parameter, alone or nullable, against that type parameter's bound, as it
already did for a bound that names a plain PHP trait. A bound PHP's own
type checks needs no check, and a type parameter nested in a type still
matches any type argument, so `count<TItem : DatabaseEntity>(
PaginatedList<TItem> page)` still takes a raw page.

sharp/mago/crates/sharp-bridge/
├── src/lower/types.rs            checked_text checks the bound
└── tests/lower.rs                a row per form
Zend/tests/sharp/
├── TypeArgumentsChecks.sharp     boxed, maybeBoxed, Rack.add
└── type_arguments_entry_unresolved.phpt
…sors

A generic class's static whose initial value runs as code, and a static with
accessors, compile and run for each type argument, spec section 11.

- The class's hidden `#entry` takes its type arguments as its own, returns
  their entry of the statics store by reference, and runs each initial value
  that runs as code on the call that adds the entry.
  `\Sharp\Internal\statics` gets `?bool &$created = null` for it.
- Every access calls `#entry`. A static's `name#get` and `name#set` take the
  class's type arguments, keep their storage in the entry, and a `static lazy`
  value is kept under a key that holds the type arguments.
- A PHP# property's initial value and accessor bodies name its class's type
  parameters in a type, as a method's body does.
A static read through `#entry` cost 2.03 times master's in the interpreter.
`#entry` now declares no return type, so PHP checks none on each access, and a
class whose initial values are all constant returns the store's entry directly.
A read now costs 1.86 times master's in the interpreter, 1.78 under opcache and
1.84 under the tracing JIT.

A PHP# method with neither parameters nor a return type skipped its
ZEND_SHARP_RECV_TYPE_ARGS, so it read type arguments its frame never got.
`#entry` is the first such method, and zend_compile_params now emits the
receive on that path too.
The note gives each rule its state on master and what this branch builds, the
three settled questions, the final shape of generic statics with its measured
cost, and where the entry bound and the default body's bound were built. The
properties note's static rows and the generics note's "Left as they are" say a
generic class's statics are built.
…ments

The generic statics bridge test read `Tally<Order>.doubled`, which lowers
through `static_property`. A write lowers through `accessor_call`, and no row
ran the line that adds the type arguments to `doubled#set`.
A refinement gives `Proof\Box` the type parameter `T : Spec`, so a PHP# type
names its type argument, spec section 11. The caller's result is
`Box<Special>` in one run and `Box<Spec>` in the other, and `Box` is
invariant, so the caller returns `Any`. The test checks the compiled key and
its inputs, which the result type does not change.
`public static int next { get; } = Plain.total + 1;` was read as a constant
expression, since PHP#'s `Plain.total` and `Limits.MAX` both parse as a member
access. The checker refused it in the same file, the analyzer read `total` as
a class constant, and the engine got PHP's constant default
`Plain::total + 1`.

`Property::initial_value_runs_after_class` now also holds when a static
member's initial value reads `Class.name`, and the checker and the analyzer
ask it, as the bridge already did, so the value runs once as code, in
`#statics` or a generic class's `#entry`. A class constant or an enum case read
there runs as code too, with the same value.
…ain PHP

A plain PHP call of `Rack::put<TSub : TItem>` or `Rack::boxed<TBox :
Box<TItem>>` aborted the engine: `Lowering::parameter_metadata` wrote the
bounds as written, with the class's type parameter as `$0`, which reads it
from `this`, which a static call has none of. The bounds are now written with
`type_text`, as the checks are, so a static method reads the class's type
parameter as its own leading `#0`.
…ument

`Function<void()> found = () => this.find("x");` fixed `find`'s `T` as `void`,
because `closure_result_type` gave the lambda's body the function type's
`void` result as its declared type. A `void` result now gives none, as a
`void` method's body gets none, so the call is refused for the type argument
nothing fixes.
`Box<Order> passed() => this.call(() => this.make());` was refused: "Nothing
fixes the type argument `T` of the call to `Infer.make`." The declared type
the call's result goes into fixes `call`'s `T`, and spec section 11 says the
lambda's result goes into `T`, but only a non-lambda argument took the
parameter type that the declared type fixed. A lambda argument now takes it
too, so both calls are fixed and the variance help no longer shows there.
`public static Order sorted { get; } = Order.Ascending;` ran in `#statics`
since a static's initial value that reads `Class.name` runs as code, and an
enum case or constant is no static. PHP# names a property or method in camel
case and a constant or enum case with a capital, which the checker enforces,
so only a read of a lowercase name runs as code. The checker, the analyzer
and the engine still share the one rule.
…r type arguments

`Sub<Order>.count` for `Sub<TX> : Base<Box<TX>>` threw "Using $this when
not in object context": the statics' type arguments kept the header's `TX`
unreplaced. The access's type arguments now replace the subclass's own type
parameters in its header, so it reads `Base<Box<Order>>`'s statics.

`TB.count` for `TB : Base<Order>` read `Any?`'s statics. A type parameter
now passes its bound's type arguments, which the type argument the code runs
with fits, as a class value passes those of its type. Static calls take the
same type arguments.
`is_joining_bound` checks that a bound is `Object`, a class, an interface,
a generic class type or several of them joined with `&`: a class bound.
`new Shelf()` of a plain PHP `@template` class compiled and inferred its
template from the constructor's arguments, while `new` of a PHP# class and a
type of either needed the type arguments. `new` and a type now call one
check, `report_missing_type_arguments`, which reports "`Shelf` needs its type
argument." with `Shelf<TItem>` to write. Only a type test, now
`HintPlace::TypeTest` in place of `tested: bool`, and a static member leave a
plain PHP class alone. The PHP#-only check it wrapped is gone.

Swept: `Zend/tests/sharp/IndexRead.sharp` writes `new SplFixedArray<int>(3)`,
the analyzer and bridge tests write the type arguments on each such `new`,
and the spec names `new` in the rule.
`Collection.make([new Order()])` into `Collection<int, Order>` reported
"expected `Collection<int, Order>`, but found `Collection<int, Order>`", and
`Box<int> b = Factory.of(5)` reported "Box<int> cannot be used as Box<int>.".
Inference fixed the type argument from the value as is: the key of a list is
`non-negative-int` and `5` is the literal `5`, which PHP# shows as `int` but
which an invariant type parameter refuses.

In PHP#, the lower bound an argument gives a type parameter is now the type
PHP# writes, `written_type_argument`: each scalar its general type, each enum
case its enum, and each array its `List`, `Map` or `Set`, as C# and Kotlin
have no literal types and TypeScript widens the literal it infers. The
engine's recorded type arguments take the same function, which moved from
`artifacts.rs` to `utils/template.rs`.
`public struct Pair<TFirst, TSecond>` declares type parameters, as a
class does, with bounds, markers and the naming rule. The struct was
refused whole until generics landed.

- `==` reads each property with the operand's type arguments, so
  `Pair<int, string>` compares and `Pair<Plan, int>` is refused,
  naming `Plan`.
- `Map<Pair<int, string>, int>` keys by value. The engine's struct hash
  skips the hidden slot of the type arguments.
- `Pair<int, string>.parse` and `tryParse` take the type arguments as
  a static method does, give them to the object, and check each field
  against them, a field of a generic struct too. A field of a type
  parameter reads only as the input holds it, so a type argument that
  `parse` builds first is a compile error that says why.
- Each type argument has its own statics, through `#entry`.
- The fingerprint hashes a struct's type parameters.
- The generated `parse` and `tryParse` count as no use of a type
  parameter and break no variance marker, as a constructor does.
…rite

A throw in a generic static's initial value left the static out of its
type argument's entry. A later read threw `OutOfRangeException:
Undefined array key "made"`, and `+=` or `++` warned and wrote a value
built from null. A class that isn't generic throws "Typed static
property App\Counter::$made must not be accessed before initialization"
on each of those, and a write sets the static.

A static whose initial value runs as code now does the same in a
generic class. The codex marks it with `RUNTIME_INITIAL_VALUE`, so an
access in any file knows it.

- A read checks the entry only when the value it reads is not there
  or null: `#entry(...)['made'] ?? (array_key_exists(...) ? null :
  throw ...)`. It costs 5.3 instructions a read.
- A compound assignment, `++` and `--` check inside the index, through
  a hidden `$statics#N` bound to the entry, which PHP runs before the
  fetch. Each update takes its own name, since PHP runs every index of
  a chain before it fetches.
- `=` and `??=` set the static, and a static's accessors read their
  storage the same way.
`built_part` read a `List` type argument's known elements, which only a
literal's type has. A type argument of `parse` is written, as
`List<Address>`, so the branch never ran.
Master gained #144, CI's base images, and #147, sharp/bin/spec writing
each type of an example to a file of its own. SPEC_GUARD compares this
branch with master's tip, so it read master's sharp/bin/spec change as
this branch's.
@heyJordanParker
heyJordanParker merged commit 4e4ac5f into master Oct 16, 2026
20 checks passed
heyJordanParker added a commit that referenced this pull request Oct 16, 2026
Master brings #142, #146, #147, #148 and #149. Each conflict keeps both
sides' behavior:

- A lambda's result type: master's `AnalysisArtifacts::lambda_result` is
  the one mechanism. `try` in a lambda reads it, and #143's
  `BlockContext::lambda_result_type` with its setters is gone.
- A `match`'s declared type reaching its PHP and its arms: master's code,
  with `Expression::Match` kept in `takes_declared_type`, without which
  the PHP `match` takes no declared type.
- `==` on a struct or a case: master's per-side type arguments for a
  generic struct, and a generic enum's case fields read the enum's type
  arguments from the side that gives them, through `with_type_arguments`.
- A call's declared type: master's `declared_return_type` goes through
  `as_declared_ancestor`, so `Result.Ok(…)` into a `Result<int, E>` fixes
  the case's type arguments for the arguments and for the result.
- The bridge: master's `generic_statics`, with `class_metadata` taking the
  class it describes, as a generic enum's case needs.
- Spec section 11 keeps master's inference bullets and #143's rule for a
  static call of a generic class.
heyJordanParker added a commit that referenced this pull request Oct 16, 2026
Problem

#145 was behind master, which gained #142, #143, #144, #146 to #150.
Both sides changed the default names: this branch generates them from
the standard library into `SHARP_CLASSES`, and #143 added `Result` to a
hand-written list and made `Error` a default name nothing shadows.

Solution

One mechanism: `default_classes()` stays `NAMED_EFFECTS` plus the
generated `SHARP_CLASSES`, regenerated from the merged library, which now
holds `Sharp\Error` and `Sharp\Result`. #143's `fixed_default_class`
stays, and `default_classes()` leaves out the class it fixes, so `Error`
is never shadowable while `Result` is.

sharp/mago/crates/names/src/
├── lib.rs                 default_classes and fixed_default_class
├── sharp_classes.rs       regenerated: Error and Result join
└── internal/walker.rs     both imports kept
docs/architecture/slices/23-names-imports.md   Error is the one fixed default name
@heyJordanParker
heyJordanParker deleted the feat/generics-rest 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