Skip to content

feat: section 22, inheritance: default bodies, super<Interface>, plain PHP traits and one body per member - #133

Merged
heyJordanParker merged 25 commits into
masterfrom
feat/inheritance
Oct 15, 2026
Merged

heyJordanParker merged 25 commits into
masterfrom
feat/inheritance

Conversation

@heyJordanParker

@heyJordanParker heyJordanParker commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Completes: §22

Problem

Section 22, inheritance, had two spec examples in sharp/baseline/spec: interface-defaults and plain-php-traits. PHP# refused an interface's default bodies and a plain PHP trait in a class header. It had no final override, no way to reuse one of two interfaces' bodies for one method, and no check that a class gets one body per method.

Solution

Every section 22 rule now compiles, refuses or runs as the spec annotates, in the checker, the bridge and the engine.

  • Default bodies. An interface's method or computed property with a body is a default body. The interface compiles to a PHP interface whose members are all abstract, and a trait <Interface>\Defaults in the same compiled file holds the bodies. Each PHP# class, struct, enum, event and data-enum class that implements the interface uses the trait. A plain PHP class writes use HasDesign\Defaults;. Engine: inheritance_defaults.phpt.
  • Computed properties. string designTag => …; in an interface lowers to public mixed $designTag { get; }, and the trait's protected method designTag@App\HasDesign holds the body and checks its type. Each class that gets the body declares public mixed $designTag { get => $this->{'designTag@App\HasDesign'}(); }. The interface's property is mixed because PHP refuses a typed property that implements an untyped interface property, so an override, stored or computed, keeps its own PHP type, and a plain PHP class writes public string $designTag. Replacing it takes override. An enum has no property, so an enum that implements the interface is an error that names the property.
  • Generic interfaces. A default body reads the type arguments each class gives the interface, in its header or through an interface that extends it. The trait carries the header App.Keyed<$0>. The engine maps a trait's code to that interface, and a method a class took from a trait back to the trait by the op array they share. So value is TKey, new Box<TKey>() and the checks of a call from plain PHP use the class's type arguments. A default body of Handler<T> runs the narrower handle(Order) a class writes through Run section 6's fields and properties on the engine #132's widened parameter. Engine: inheritance_defaults.phpt, handlers.phpt.
  • One body per member. When two places give a class a body for one method or computed property, the class writes the member itself, or the class is the error ambiguous-inherited-member that names both. The places are two interfaces' default bodies, a default body and a plain PHP trait, two header traits, a header trait's property and a computed default, or a default body and the base class. A header trait replaces the base class's method, as PHP's use does, so Post : Model, SoftDeletes, HasUniqueStringIds compiles and runs.
  • Sub-interfaces. A sub-interface replaces its parent's default body with override, and the most specific interface's body wins, as in Java, C# and Kotlin. The class's use takes it insteadof the parent's, and super<Shows> still runs the parent's. The spec gains the rule and the example sub-interface-defaults.
  • super<Interface>. super<HasLabel>.label() runs one interface's default body, in the class and in its subclasses, through the protected alias label@App\HasLabel the class's use gives each default body. It names an interface the class implements. A subclass of a plain PHP class that uses the trait is an error that names that class. super and super<X> are only the object of a method call. A call of an abstract parent method is the error abstract-super-call. In a static method, super.name(), super<X>.name() and Self.name() of an instance method are an error, since a static method has no this.
  • Plain PHP traits. A trait in the header of a class, struct, enum or event lowers to PHP's use, and a generic one takes type arguments, as HasFactory<OrderFactory>. A trait is a type: is, a parameter, a List element, an & bound and a method's type parameter bounded by a trait test it through sharp_object_is. PHP# code never names X.Defaults. Engine: class_header_trait.phpt, inheritance_trait_types.phpt.
  • Overrides. final override stops an override chain, and final without override is an error. Implementing an abstract interface member takes no override. Modifier pairs that can't matter, such as private virtual, are errors that say why. Engine: inheritance_final_override.phpt.
  • One method per name. A second method of one name in one class is an error that says to name it by what it takes. The spec says it under methods.
  • Plain PHP interfaces that extend BackedEnum. A PHP# backed enum implements one, as enum Align : string, Aligned. The engine writes the enum's from, tryFrom and cases, which take int|string as PHP's own do, so the interface check skips each method BackedEnum or UnitEnum declares, wherever the enum gets it from. Engine: inheritance_backed_enum.phpt, through the interface for a string-backed and an int-backed enum.
  • Autoload. sharp/composer/autoload.php reads a .sharp file once and maps X\Defaults to the interface's file, so a class that links its trait before its interface finds both.

Verification

  • sharp/bin/test Zend/tests/sharp: 283 of 283 pass. --opcache --repeat over the nine tests this PR changes: 9 of 9 in each of the four modes.
  • sharp/bin/test --passes over the nine tests this PR changes: every run passes.
  • sharp/bin/spec: "Checked 200 examples, ignored 1, and 32 fail", equal to sharp/baseline/spec.
  • sharp/bin/spec --base origin/master: "0 entries join sharp/baseline/spec, 2 leave it." --completes on this body: "§22: all 10 checked examples pass."
  • mago: the analyzer, semantics, syntax, names, codex, orchestrator and sharp-bridge suites pass, and clippy on each changed crate.
  • mago analyze of sharp/phpunit/vendor, plain PHP, prints the same 13227 lines on master and on this branch.

Two section 22 examples fail on master, and probing every rule line
found more: a plain PHP trait as a type compiles and runs wrong, super
of an abstract method compiles and throws, and final override is
refused. Nothing builds an interface's Defaults trait, so plain PHP
cannot use it either.

The note gives every rule of section 22 its observed state and its
mechanism, before anyone builds:
- A header trait lowers as use, decided by the bridge from the
  codebase, beside the extends and implements it already writes
- An interface's default bodies lower to the trait <Interface>\Defaults
  in its own file, which every PHP# class, enum and event that
  implements it uses, and which X\Defaults autoloads with X
- A trait type takes #102's path for a type PHP cannot test
- Seven questions for Jordan, and the boundaries with properties,
  generics and extensions

docs/architecture/slices/
└── 22-inheritance.md    <- added
…ifiers that can't matter

Spec section 22 gives an interface method a default body and lets
final override stop an override chain. The checker refused both, an
interface field got PHP's words and a refusal, and modifier pairs such
as private virtual compiled with no error.

- An interface method's block or expression body is its default body,
  checked as a class method's body, and a bare member name in it names
  this.
- An interface field is one error in PHP#'s words.
- final marks only an override, and lowers to PHP's final.
- virtual on a private method, a constructor, an abstract method or an
  override, and final or virtual in a final or static class or an
  enum, is an error that says why.
- virtual or override before an interface method gets the checker's
  modifier error instead of a parse error.

sharp/mago/crates/
├── syntax/src/parser/internal/class_like/method.rs   <- virtual and override start a member's modifiers
├── names/src/internal/walker.rs                      <- an interface's member names
├── semantics/src/internal/checker/
│   ├── sharp.rs                                      <- default bodies, interface fields, check_method_modifiers
│   └── class_like/{method,mod}.rs                    <- PHP's interface body and field errors skip .sharp files
├── semantics/tests/sharp.rs
├── sharp-bridge/src/lower.rs                         <- final on a method
└── sharp-bridge/tests/lower.rs
…r name

Spec section 22 lists a plain PHP trait in a class header and gives
interfaces default bodies. The analyzer refused a header trait as a
non-interface, knew no trait of default bodies for plain PHP to use,
and let override, super and two classes in a header speak PHP.

- A header trait moves to the class's or enum's used traits in the
  populator, and the analyzer checks it as PHP's use.
- A PHP# interface's default bodies register as the trait
  <Interface>\Defaults, and the interface's own methods stay abstract.
  Each PHP# class-like that implements the interface first uses it, so
  a plain PHP class gets the bodies only through use.
- One method per name, Jordan's ruling: a class that gets one method's
  body from two places, header traits, default bodies or its base
  class, is ambiguous-inherited-member until it writes the method.
- override marks a replaced trait method or default body, and an
  implemented abstract interface method takes none.
- super of an abstract method is abstract-super-call, and a closed
  method and two base classes speak PHP#.

sharp/mago/
├── crates/codex/src/
│   ├── lib.rs                     <- defaults_trait_name
│   ├── metadata/mod.rs            <- get_defaults_traits, get_defaults_interface
│   ├── scanner/mod.rs             <- register_defaults_trait
│   ├── scanner/function_like.rs   <- an interface method is open
│   └── populator/                 <- header traits, defaults traits, overrides of trait bodies
├── crates/analyzer/src/
│   ├── code.rs                    <- ambiguous-inherited-member, abstract-super-call
│   ├── resolver/static_method.rs  <- super of an abstract method
│   └── statement/class_like/      <- header trait uses, check_methods_given_twice, messages
├── crates/analyzer/tests/sharp.rs
└── scripts/regen-analyzer-issue-codes.php
The engine got a PHP# interface's default bodies inside the interface,
which PHP refuses, and a header trait in the implements list.

- An interface's methods lower without a body, and its default bodies
  lower as the trait HasDesign\Defaults after it, in the same file.
- A class, an enum and an event start with one use of the traits
  Types::used_traits lists: its header traits, then the Defaults traits
  of the interfaces it implements first. A subclass repeats neither.
- A header's interface list leaves its traits out.

sharp/mago/crates/sharp-bridge/
├── src/lower.rs        <- signature, defaults, trait_use; headers skip traits
├── src/lower/types.rs  <- DeclarationKind::Trait, Types::used_traits
└── tests/lower.rs
A plain PHP class that implements a PHP# interface writes
use HasDesign\Defaults; to get its default bodies, and no file is named
for that trait, so PHP found no trait.

- autoload.php loads X when X\Defaults is asked for, through the class
  map and PSR-4, since X's compiled file declares both.
- library_autoload.phpt runs a plain PHP class that uses
  App\Timed\Defaults, in both layouts.

├── sharp/composer/autoload.php
└── Zend/tests/sharp/
    ├── library_autoload.inc
    └── library_autoload.phpt
…ault body

Jordan's one-method-per-name ruling makes a class write a method that
two places give a body, and the class needs a way to reuse one of
those bodies in its own.

- The parser reads super<HasLabel> as Expression::SuperOf, the object
  of a call, and the semantics checker allows it only there.
- The analyzer resolves the call to the HasLabel\Defaults method, and
  reports super<…> outside a class, naming an interface the class does
  not implement, and a method with no default body. A class whose base
  class already implements the interface is not supported yet.

sharp/mago/
├── composer/src/Sdk/Syntax/NodeKind.php      <- SuperOf, regenerated
└── crates/
    ├── syntax/src/cst/cst/super_of.rs        <- new: SuperOf
    ├── syntax/src/{cst,parser,walker}/       <- SuperOf node, parse, walk
    ├── names/src/internal/walker.rs          <- resolves the interface
    ├── semantics/src/internal/checker/sharp.rs
    ├── analyzer/src/resolver/class_name.rs   <- resolve_super_of
    ├── analyzer/src/resolver/static_method.rs <- the Defaults trait's method
    └── */tests/sharp.rs
Hand-resolved, keeping both sides:
- syntax, walker, NodeKind.php: GenericClass and SuperOf both join the
  expression nodes.
- populator/hierarchy.rs: the header loop that moves header traits to
  used traits also moves a header parent's type arguments from
  implements to extends, as #102 does.
- analyzer class_like/mod.rs: header names come from
  Inheritance::names(), and a trait among them is a header trait;
  check_sharp_reached_twice and the PHP# variance checks run beside the
  trait checks over header traits.
- bridge lower.rs and types.rs: class_header and name_list read
  Inheritance::names() and leave traits out; a method's parameter
  metadata and its optional body both stay; Types::used_traits sits
  beside #102's type-argument queries.
- names walker: an interface enters its type parameters and its member
  names.
- semantics: the interface and method doc comments and the Signature
  text name both type parameters and default bodies.
PHP runs a trait method the class replaced only through an alias, so
super<HasLabel>.label() had nothing to lower to.

- The class's use gives each default body it calls this way a private
  alias, \App\HasLabel\Defaults::label as private label@App\HasLabel.
  No PHP# member name holds @, so the alias can't clash with one.
- The call lowers to $this->{'label@App\HasLabel'}(...).
- A class and an enum build their use after their members, so it holds
  every alias the members call.

sharp/mago/crates/sharp-bridge/
├── src/lower.rs     <- super_of_call, super_alias, aliases in trait_use
└── tests/lower.rs
…on the engine

Each rule of spec section 22 the bridge lowers now runs on the engine,
in every opcache mode, every optimizer pass and both JITs.

- class_header_trait.phpt: a header trait alone, beside a base class
  and in an enum header gives its field, method and constant, and
  class_uses and getTraitNames list it as PHP's use does.
- inheritance_defaults.phpt: default bodies run in a PHP# class, an
  enum and a plain PHP class that uses HasDesign\Defaults, and
  super<Told> runs one of two bodies through its private alias.
- inheritance_final_override.phpt: final override is a final method
  with #[\Override], and a plain PHP subclass can't replace it.
- The inheritance cache, preload and opcodes tests gain the traits and
  default bodies; Traits.inc compiles to the same opcodes as
  Traits.sharp.

Zend/tests/sharp/
├── harness/Traits.inc                    <- new: Lib\Document, HasSlug, Copies
├── Traits.sharp, Traits.inc              <- new: the header-trait fixture and its PHP twin
├── Inheritance.sharp                     <- new: default bodies, super<…>, final override
├── class_header_trait.phpt               <- new
├── inheritance_defaults.phpt             <- new
├── inheritance_final_override.phpt       <- new
├── class_header_inheritance_cache.phpt
├── class_header_preload.{inc,phpt}
└── opcodes.phpt
…ents test

Spec section 22 lets a trait stand where an interface does, and no PHP
value is instanceof a trait: `value is Copies` gave false and
`seed(Copies owner)` threw a TypeError for every object.

- A trait type lowers to PHP's object, and its PHP# type text makes a
  call from plain PHP check the argument and each List element.
- `is` on a trait records its tested type, so it lowers to the engine's
  type test instead of instanceof.
- sharp_object_is finds a trait that the object's class, a class it
  extends, or a trait one of them uses, uses, as class_uses lists them.

├── ext/sharp/sharp.c                                  <- sharp_class_uses_trait
├── sharp/mago/crates/analyzer/src/expression/mod.rs   <- a trait's is reads its type
├── sharp/mago/crates/sharp-bridge/src/lower.rs        <- a trait erases to object
├── sharp/mago/crates/sharp-bridge/src/lower/types.rs  <- a trait type is checked
├── sharp/mago/crates/sharp-bridge/tests/lower.rs
└── Zend/tests/sharp/
    ├── Inheritance.sharp                              <- Seeder
    └── inheritance_trait_types.phpt                   <- new
…uments

A default body of Keyed<TKey> read TKey as written, so Order : Keyed<int>
got List<TKey> from keys() and failed its own signature check.

- The trait of a generic interface's default bodies takes the
  interface's type parameters, and its methods read the trait's, as a
  @template trait's do.
- A class gives the trait the type arguments it gives the interface,
  in its header or through an interface that extends it, as @use does.
- A default body that reads the interface's type parameters while the
  code runs, in is or as a type argument of new or a call, is not
  supported yet: the engine finds type arguments on this, and the
  class holds its own, not the interface's.

├── sharp/mago/crates/codex/src/scanner/mod.rs              <- reparent_types
├── sharp/mago/crates/codex/src/populator/hierarchy.rs      <- defaults_type_arguments
├── sharp/mago/crates/analyzer/src/statement/class_like/method.rs
├── sharp/mago/crates/analyzer/tests/sharp.rs
└── Zend/tests/sharp/{Inheritance.sharp,inheritance_defaults.phpt}
…e it by what it takes

Jordan ruled that a class has one method per name, so PHP# has no
overloading by argument types. The spec said so only for named
constructors, and a second method got PHP's "class method has already
been defined", which names no fix.

- A second method, law, named constructor or extension member of one
  name in a .sharp class says it is declared twice and to give each a
  name that says what it takes, as in grantTenantAccess. Plain PHP keeps
  its message.
- docs/spec.md states the rule in section 7 with an example, points the
  named-constructor bullet at it, and states in section 22 that the
  rule holds across inherited bodies, with the super<Interface> example.
- plain-php-traits leaves sharp/baseline/spec. interface-defaults stays
  until #132 brings interface { get; set; } properties.

├── docs/spec.md
├── sharp/baseline/spec/§22/plain-php-traits          <- removed
├── sharp/mago/crates/semantics/src/internal/checker/class_like/mod.rs
├── sharp/mago/crates/semantics/tests/sharp.rs
└── Zend/tests/sharp/compile_command.phpt
Master brings generics, structs, events, readonly, class values, the
global. fix and pattern matching. Each conflict keeps both sides.

- The bridge: master's class_members holds the members of a class and a
  struct, so class() adds the header traits' use after them. A struct
  and the abstract class of an enum with a case that carries data now
  start with that use too, so a default body runs in each, with rows in
  the header-trait bridge test and inheritance_defaults.phpt.
- super<X> calls take their arguments through master's call(), as any
  method call does.
- autoload.php keeps master's rule, which reads an enum's file for one of
  its cases' classes. It also loads X\Defaults through X's file under
  PSR-4, so the branch's own Defaults branch goes. The class map gets the
  entry instead: Plugin::declaredClasses lists X\Defaults for a file
  that declares the interface X.
- A struct's second method of one name gets the one-method-per-name
  message.
- The branch's enum Tone in Inheritance.sharp becomes Mood, since master
  declares Demo\Tone.
… as inputs

A class's use names its header's plain PHP traits and the Defaults trait
of each interface with a default body. A header trait that turns into an
interface, or an interface that gains or loses its last default body,
changes what the class compiles to, so the engine must see the class's
compiled file as stale. The test pins that both files are inputs.

└── sharp/mago/crates/orchestrator/src/service/incremental_analysis/compile.rs
…it is not found

An interface's file declares the trait of its default bodies, and an
enum's file the class of each case that carries data, so autoload.php
reads that file for those names. After the interface loaded, asking for
the Defaults trait of an interface without a default body read its file
a second time and failed with "Cannot redeclare interface", under PSR-4
through the enum fallback and under the class map through the entry the
plugin lists. Reading each file once leaves PHP's own "Trait not found".

- autoload.php includes a file with include_once.
- library_autoload gains App\Ticking, an interface without a default
  body, with a row for each layout.

├── sharp/composer/autoload.php
├── Zend/tests/sharp/library_autoload.inc
└── Zend/tests/sharp/library_autoload.phpt
Master brings properties (#132), nameof, internal and too-wide members.
Each conflict keeps both sides.

- The analyzer keeps master's quiet override of a closed PHP# method by
  a plain PHP subclass, and the branch's PHP# message for a .sharp one.
- final on an override still lowers to PHP's final, and lazy adds no
  flag, as master lowers it.
- The analyzer row that gives a generic interface's default body a Box
  writes its field's initial value, since a member has no implicit one.
- sharp/bin/spec lists HasDesign\Defaults beside each PHP# interface and
  reads each file once, as autoload.php does, so the interface-defaults
  example runs and leaves sharp/baseline/spec.
…r<X> reaches it from a subclass

An interface gave only its methods default bodies, so a computed property
written there was refused. super<X> ran a default body only in a class
whose base class did not implement X, and was "not supported yet" in a
subclass, because the class's use named a private alias only when its
own methods called super<X>.

- A PHP# interface's computed property, `string designTag => …;`, is a
  default body, checked as a class's computed property is. It takes no
  static or lazy, since it runs on each read.
- It lowers to an untyped `public $designTag { get; }` in the interface
  and the trait's protected method 'designTag@Demo\HasDesign', which
  checks the value's type. Each PHP# class that gets it declares
  `public $designTag { get => $this->{'designTag@Demo\HasDesign'}(); }`,
  which a plain PHP class writes itself. It has no PHP type, since the
  class's file has none to write, so an override writes none.
- Replacing it takes `override`, and two interfaces that both give it,
  or one beside the base class's property, make the class write it.
- Every class that uses a Defaults trait gives each default body a
  protected alias, label@App\HasLabel, so super<HasLabel> works in its
  subclasses too. Only a subclass of a plain PHP class that uses the
  trait is still an error, which names that class.
- The bridge's super_aliases bookkeeping goes.

├── Zend/tests/sharp/Inheritance.sharp
├── Zend/tests/sharp/inheritance_defaults.phpt
└── sharp/mago/crates
    ├── analyzer/src/resolver/class_name.rs
    ├── analyzer/src/statement/class_like/mod.rs
    ├── analyzer/src/statement/class_like/override_attribute.rs
    ├── analyzer/tests/sharp.rs
    ├── codex/src/scanner/mod.rs
    ├── semantics/src/internal/checker/class_like/mod.rs
    ├── semantics/src/internal/checker/sharp.rs
    ├── semantics/tests/sharp.rs
    ├── sharp-bridge/src/lower.rs
    ├── sharp-bridge/src/lower/types.rs
    └── sharp-bridge/tests/lower.rs
…is only the object of a call

A generic interface's default body that read its type parameters while
the code ran, as `value is TKey` or `new Box<TKey>()`, was "not
supported yet": the engine counted the body's `$0` among the type
parameters of the class that used the Defaults trait, not the
interface's. `super.count` and a bare `super<HasLabel>` fell to the
generic "This expression is not supported yet".

- A generic interface's Defaults trait has the header `App.Keyed<$0>`.
  The engine maps a trait's code to the interface its header names, and
  a method a class took from a trait to that trait, by the op array it
  shares, so `is`, `new`, and the checks of a call from plain PHP read
  the type arguments each class gives the interface.
- The analyzer's refusal of such bodies goes.
- `super` and `super<X>` anywhere but the object of a method call are an
  error that says so, as spec section 22 defines `super` only as a call.
- Spec section 22 shows a computed property's default body, and the
  forwarding property a plain PHP class writes for it.
- A default body of Handler<T> runs the class's narrower `handle`.
- clippy: the expect allowance sits on finalize_class_like again, and
  the Defaults name doc has a short first paragraph.

├── Zend/tests/sharp
│   ├── Handlers.sharp
│   ├── Inheritance.sharp
│   ├── handlers.phpt
│   └── inheritance_defaults.phpt
├── docs/spec.md
├── ext/sharp/sharp.c
└── sharp/mago/crates
    ├── analyzer/src/statement/class_like/method.rs
    ├── analyzer/tests/sharp.rs
    ├── codex/src/lib.rs
    ├── codex/src/scanner/mod.rs
    ├── semantics/src/internal/checker/sharp.rs
    ├── semantics/tests/sharp.rs
    ├── sharp-bridge/src/lower.rs
    └── sharp-bridge/tests/lower.rs
patch-coverage found nine lines no test ran.

- A computed property that clashes with a header trait's field reports
  what the PHP twin's hooked property reports, at the property.
- A computed property's default body beside the base class's property
  makes the class write it.
- `super<Told>` as a value adds no analysis issue to the semantics
  checker's error.
- The bridge's lookups of a class it lowers are unreachable when the
  codex has no metadata, and a readonly class's missing trait has no
  branch of its own.

├── sharp/mago/crates/analyzer/src/statement/class_like/mod.rs
├── sharp/mago/crates/analyzer/tests/sharp.rs
└── sharp/mago/crates/sharp-bridge/src/lower/types.rs
… BackedEnum

`enum Align : string, Aligned`, where the plain PHP interface `Aligned`
extends `BackedEnum`, failed to compile: "Parameter `value` of
`Align.from` must take at least `int|string`, the type `BackedEnum.from`
erases it to", and the same for `tryFrom`. The interface check skipped
`BackedEnum` and `UnitEnum` only when the header named them, not when
an interface it named inherited their methods. The engine writes an
enum's `from`, `tryFrom` and `cases`, which take `int|string` as PHP's
own do, so the check now skips each method that `BackedEnum` or
`UnitEnum` declares, wherever the class gets it from, and the
whole-interface skip goes.

A string-backed and an int-backed enum implement `Lib\Aligned`, and
plain PHP runs `from` and `tryFrom` through it.

├── Zend/tests/sharp
│   ├── harness/Traits.inc
│   ├── Traits.inc
│   ├── Traits.sharp
│   ├── inheritance_backed_enum.phpt
│   └── opcodes.phpt
└── sharp/mago/crates/analyzer
    ├── src/statement/class_like/mod.rs
    └── tests/sharp.rs
- A header trait replaces the base class's method, as PHP's `use` does:
  `Post : Model, SoftDeletes, HasUniqueStringIds` compiles and runs. The
  base class counts as a second place only against a default body.
- A header trait's property beside a computed property's default body is
  two places, a compile error instead of an engine fatal.
- A sub-interface replaces its parent's default body with `override`, and
  the most specific interface's body wins: the class's `use` takes it
  `insteadof` the parent's, and `super<Shows>` still runs the parent's.
  Only the interface's signature carries `#[\Override]`, since the trait
  body has no parent. Spec section 22 gains the rule and an example.
- `super.name()`, `super<X>.label()` and `Self.name()` of an instance
  method in a static method are a compile error, since a static method
  has no `this`. The call keeps its type.
- A trait in an `&` bound leaves PHP's type to the classes beside it, and
  a method's type parameter bounded by a trait checks a call from plain
  PHP against its bound's text.
- An enum, and an enum whose cases carry data, has no property, so one
  that implements an interface with a computed default is an error that
  names the property.
- A generic plain PHP trait takes its type arguments in a header, as
  `HasFactory<OrderFactory>`: the populator moves the count to
  `template_type_uses_count`.
- An interface's computed default is `mixed` in PHP, so an override,
  stored or computed, keeps its own PHP type, and a plain PHP class
  writes its type. `Types::has_default_property` goes, and
  `default_properties` is `default_body_properties`.
- PHP# code naming `X.Defaults`, in an import, a header or a test, is an
  error.
- A struct's and an event's header name a trait, which lowers to `use`.
- The two alias comments say protected, and the design note says what
  ships for decision 8, line 150 and question 2.

├── Zend/tests/sharp
│   ├── Inheritance.sharp, Traits.sharp, Traits.inc, harness/Traits.inc
│   ├── class_header_trait.phpt, opcodes.phpt
│   └── inheritance_defaults.phpt, inheritance_final_override.phpt, inheritance_trait_types.phpt
├── docs/spec.md, docs/architecture/slices/22-inheritance.md
└── sharp/mago/crates
    ├── analyzer: lib.rs, resolver/static_method.rs, statement/class_like/{enum_case,mod,override_attribute,struct}.rs, tests/sharp.rs
    ├── codex: populator/hierarchy.rs
    ├── semantics: internal/checker/sharp.rs, tests/sharp.rs
    └── sharp-bridge: src/lower.rs, src/lower/types.rs, tests/lower.rs
Patch coverage found two lines no test ran: `default_body_properties`
keeping a sub-interface's computed property over its parent's, and a
`None` arm in `checked_text`'s trait test.

- The bridge row for a sub-interface's default body gives both
  interfaces a computed `tag`, and `Fancy` declares one `tag`, which
  runs `tag@App\ShowsMore`.
- `checked_text` tests each part of a type for a trait in one
  `matches!`, so it has no arm left without a test.
@heyJordanParker
heyJordanParker merged commit cb3f094 into master Oct 15, 2026
22 checks passed
heyJordanParker added a commit that referenced this pull request Oct 15, 2026
Two conflicts. The semantics checker runs master's `check_method_modifiers`
beside `check_abstract_access` and `check_iterator_returns`. The bridge
keeps master's `method_declaration`, which an interface's `signature`
shares, with this branch's `private` default for a method with no access
modifier and the PHP# callee its parent constructor call checks lazy
sources against.

Master's `super_of_call` passes its PHP# callee to `call` too, and two
of master's bridge tests show the result type a method with no function
type now carries.
@heyJordanParker
heyJordanParker deleted the feat/inheritance 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