Skip to content

fix: run lines take their services from the container, as PHP# code does - #148

Merged
heyJordanParker merged 4 commits into
masterfrom
fix/spec-plain-php-run
Oct 16, 2026
Merged

heyJordanParker merged 4 commits into
masterfrom
fix/spec-plain-php-run

Conversation

@heyJordanParker

@heyJordanParker heyJordanParker commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Run lines get a foreign object the way PHP# code does: through a constructor, from a module binding. This lands ahead of the section 29 PR, because SPEC_GUARD judges a PR with the base's sharp/bin/spec.

Problem

Section 29 makes creating a foreign object outside a module binding a compile error. The environment example's run line does exactly that:

<!-- run environment
new Deploy(new Environment()).target();   // throws OutOfRangeException
-->

The run class was always created without its constructor, so a run line had no way to get a foreign object except new.

What changes

  • The run script in sharp/bin/spec fills the run class's constructor parameters from Sharp\Container, as the container fills a bound class's constructor. It reads the standard library's module first, as the library's Composer autoload does, so Environment is bound. A run class with no constructor parameters is created as before.
  • sharp/spec-self-test.md gains run-takes-services: a Gauge holds an Environment through a module binding, and its run lines declare public ExampleRun(private Gauge gauge) { }.
    • With the container fill off: "throws Error: Typed property App\ExampleRun::$gauge must not be accessed before initialization".
    • With the module read off: "the run threw Sharp\ContainerError: No module binds Sharp\Environment for App\Gauge".
  • docs/architecture/spec-examples.md says how run lines reach a foreign object.

The section 29 PR then shows the environment claim with a visible module block and these run lines:

<!-- run environment
public ExampleRun(private Deploy deploy) { }
this.deploy.target();   // throws OutOfRangeException
-->

Verification

Run on this branch, which starts at master 849232f4e1, with the engine and mago built from that commit:

  • sharp/bin/spec --self-test: 22 of 22 self-test examples give the problems they expect.
  • sharp/bin/spec on master: "Checked 201 examples, ignored 1, and 16 fail."
  • sharp/bin/spec on this branch: "Checked 201 examples, ignored 1, and 16 fail." The 16 are the same examples: §2 keyword-case, §7 variadic-parameters, §8 standard-library-calls, §8 output-and-exit, §9 parameter-member-limits, §11 generic-method-inference, §11 type-parameter-bounds, §18 template-to-string, §19 operators, §27 one-type-per-file, §27 position, §29 pure-interface, §29 function-effects, §31 result-enum, §31 try-propagation, §31 error-interface.

…ne does

Problem: section 29 makes creating a foreign object outside a module a
compile error, and the environment example's run line does exactly that:
new Deploy(new Environment()).target(). A run line is PHP#, and it is the
only line sharp/bin/spec lets restate a throws on a method's line, so the
example cannot keep its claim once the rule holds.

Solution: check_reached also counts a running line of a plain PHP
statements block of the same example as restating a claim. Plain PHP may
create the object, so the section 29 PR moves the claim to such a block.
The self-test gains restated-by-php, which stops the check when the rule
is switched off. Every spec example passes or fails as before: 201
checked, 1 ignored, and the same 16 fail.

sharp/
├── bin/spec             check_reached: a plain PHP line restates a claim
└── spec-self-test.md    restated-by-php
docs/architecture/
└── spec-examples.md     which lines restate a claim
Problem: spec section 29 makes creating a foreign object outside a module
binding a compile error, and the environment example's run line does
exactly that: new Deploy(new Environment()).target(). The previous commit
moved the claim to a plain PHP block, which teaches a reader that making
an Environment takes plain PHP. PHP# code gets a foreign object through
its constructor, from a module binding.

Solution: the plain PHP restatement is gone, so only a run line restates
a claim again. A run line may declare the run class's constructor, and
the run script fills each parameter from Sharp\Container, as the
container fills a bound class's constructor. The script reads the
standard library's module first, as its Composer autoload does, so
`Environment` is bound. A run class with no constructor parameters is
created as before. The self-test's run-takes-services gets a Gauge that
holds an Environment through a module binding. Without the container
fill its run reads an unset field, and without the module read the
container finds no binding for Sharp\Environment.

Every spec example passes or fails as before: 201 checked, 1 ignored,
and the same 16 fail.

sharp/
├── bin/spec             runner: run_entry fills a constructor from the container
└── spec-self-test.md    run-takes-services replaces restated-by-php
docs/architecture/
└── spec-examples.md     run lines reach a foreign object through a constructor
@heyJordanParker heyJordanParker changed the title fix: a plain PHP line of a spec example restates a claim, as a run line does fix: run lines take their services from the container, as PHP# code does Oct 16, 2026
heyJordanParker added a commit that referenced this pull request Oct 16, 2026
The example showed its throws claim through a plain PHP block, which taught a reader that creating an Environment takes plain PHP. It now shows a module binding of Deploy, and its run lines take the Deploy through a constructor, as PR #148 lets a run do. With #148's runner and this branch's checker, the environment example passes and the same 16 examples fail.
@heyJordanParker
heyJordanParker merged commit 5ca30ce 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
heyJordanParker deleted the fix/spec-plain-php-run 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