Skip to content

fix: a spec example finds an interface's Defaults trait in the interface's file - #137

Merged
heyJordanParker merged 1 commit into
masterfrom
fix/spec-interface-defaults
Oct 15, 2026
Merged

heyJordanParker merged 1 commit into
masterfrom
fix/spec-interface-defaults

Conversation

@heyJordanParker

Copy link
Copy Markdown
Owner

Problem

A PHP# interface with default bodies compiles to the interface and the trait <Interface>\Defaults, both in the interface's file. PHP links a class's traits before its interfaces, so a spec example's class that implements the interface asks the autoloader for App\HasDesign\Defaults first. sharp/bin/spec mapped only the names a file declares at its top level, so the lookup found nothing and section 22's interface-defaults example could never pass.

Solution

declared_names() also lists <Interface>\Defaults for each PHP# interface a file declares. The runner's autoloader reads a file with require_once, since the trait and the interface now name one file. sharp/composer/autoload.php makes the same change for an app in #133.

SPEC_GUARD requires a change to sharp/bin/spec in a PR of its own, so this lands ahead of #133. The section 22 examples that use it run in #133, whose compiler builds default bodies. Master's compiler refuses them, so no self-test example can show the rule before #133 lands.

Verification

…ace's file

A PHP# interface with default bodies compiles to the interface and the
trait `<Interface>\Defaults`, both in the interface's file, spec section
22. PHP links a class's traits before its interfaces, so a class that
implements the interface asks the autoloader for `App\HasDesign\Defaults`
first. sharp/bin/spec mapped only the names a file declares at its top
level, so that lookup found nothing and the example could never pass.

declared_names() now also lists `<Interface>\Defaults` for each PHP#
interface a file declares, and the runner's autoloader reads a file with
require_once, since the trait and the interface now name one file. This
is the change sharp/composer/autoload.php makes for an app in #133.

The section 22 examples that use it run in #133, whose compiler builds
default bodies. Master's compiler refuses them, so no self-test example
can show the rule before #133 lands.

sharp/
└── bin/spec    declared_names lists X\Defaults, the autoloader uses require_once
@heyJordanParker
heyJordanParker merged commit 25b0055 into master Oct 15, 2026
19 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 fix/spec-interface-defaults 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