Skip to content

fix: a PHP form PHP# never has is refused for good, with what PHP# writes instead - #166

Merged
heyJordanParker merged 12 commits into
masterfrom
fix/permanent-refusals
Oct 18, 2026
Merged

heyJordanParker merged 12 commits into
masterfrom
fix/permanent-refusals

Conversation

@heyJordanParker

@heyJordanParker heyJordanParker commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

Problem

The checker refused PHP forms PHP# will never have with "This … is not supported yet in PHP#.", which promises a feature that is not coming. docs/v1.md says "The checker refuses nothing as 'not supported yet'."

Solution

Each retired form gets a permanent refusal that names the form as written and what PHP# writes instead, in PHP#'s words. Each suggested form compiles. For example:

PHP# has no `instanceof`: write `extra is Report`.
PHP# has no `elseif`: write `else if`.
PHP# has no `.=`: append with `+=`.
PHP# has no `eval`: write the code as a method, and call it.
PHP# has no `public(set)`: give the property `{ get; set; }`.
PHP# has no `use` in a class: list `Shared` in the header after `:`.
PHP# has no `parent` type: write `Base`, the class's base class.
A method name can't start with `__`: write `toString`, which every conversion to text calls.
A method name can't start with `__`: PHP# never calls it for you: give it a camelCase name and call it.
A local keeps no value between calls: keep it in a `private static` field of the class.
`[a, b]` can't be written to: unpack a tuple into new locals with `const [a, b] = …`.
`required` goes on the constructor or a property, never on a method: remove it here.
A constant value can't read `Calc.rate.cents`: it holds literals, constants and the operators on them.

== on an Iterable, or on a type parameter bound by a collection, names toList(): "== compares a List, a Map or a Set, and an Iterable is none of them: compare a.toList() == b.toList()." A .sharp file the engine refuses leaves PHP's included files, so a second require_once reports the same refusal.

The generic refusal says "This … is not part of PHP#.", and it never names a PHP# form. The forms PHP# has not decided keep "not supported yet": is_undecided in the semantics checker names them, and every expression in a constant value but a call and a member read is one.

sharp/spec-self-test.md's refusal example now writes ? : in a constant, because new Cart; is no longer a "not supported yet" refusal.

Verification

  • cargo test -p mago-semantics --test sharp: 426 passed.
  • cargo test -p mago-syntax --test sharp: 240 passed.
  • cargo test -p mago-analyzer --test sharp: 1034 passed, with rows that compile every form a refusal names.
  • cargo test -p mago-sharp-bridge --test lower: 446 passed.
  • cargo clippy on the changed crates with -D warnings: clean.
  • sharp/bin/spec: "Checked 236 examples, ignored 1, and 0 fail."
  • sharp/bin/spec --base <master>: "0 entries join sharp/baseline/spec, 0 leave it."
  • sharp/bin/test and sharp/bin/test --opcache on refusal_required_again.phpt and the refusal tests: all pass.
  • mago compile of Zend/tests/sharp: "Compiled 492 PHP# files".

…ites instead

Problem

The checker refused PHP forms PHP# will never have with "This … is not
supported yet in PHP#.", which promises a feature that is not coming.
docs/v1.md says "The checker refuses nothing as 'not supported yet'",
and a PHP# user should never need to know the PHP underneath to fix a
refusal.

Solution

Each retired form gets a permanent refusal that names the form as
written and what PHP# writes instead, in PHP#'s words: `elseif`, a
`trait` declaration, a trait's `use` in a class, `extends` and
`implements`, a modifier a type, a constant, a field or an accessor
does not take, `public private(set)`, `iterable`, the `parent` type, a
parenthesized type that is no union, a header type that is no class or
interface, `<>`, `instanceof`, `.=`, `&`, `(unset)` and `(void)`,
heredoc and nowdoc, `new Report;`, a method name that starts with `__`,
a method named after its class, `required` on a method or an operator,
the accessor forms, an initial value before the accessors, a write to a
target that can't be written, a second, braced or global namespace, a
declaration inside a method, `goto` and labels, `clone`, `include` and
`require`, `new` on an expression that is no class name, a call in a
constant value, a law in an interface, a case in a class, a missing
list element, and a member name written as an expression.

The generic refusal says "This … is not part of PHP#." Only the forms
PHP# has not decided keep "not supported yet", each named in
`is_undecided`: `break` and `continue` with a level, an anonymous class,
`|>`, a partial application, `Self.name`, an interface constant, an
interface property body, an operator in an interface or an enum, `? :`,
indexing, a template and a cast in a constant, an intersection type, a
type test on a tuple or `Class<T>`, and a constant typed as a function,
a tuple or an `Iterable`. The analyzer, the parser and the other
checker arms keep their own: attribute targets, `==` on a `Set`, a
`Set` event parameter or case field, a static constructor, `new
TItem.from()`, a null-safe write and a data-carrying enum case in a
constant.

sharp/spec-self-test.md's refusal example writes `? :` in a constant,
because `new Cart;` is no longer a "not supported yet" refusal.

php-sharp/sharp/
├── spec-self-test.md                           the refusal example
└── mago/crates/
    ├── analyzer/
    │   ├── src/expression/access/mod.rs        `new Report.of` names `new Report.of()`
    │   └── tests/sharp.rs                      the rows for `new`, `.=` and a trait's `use`
    ├── hir/src/lower/error/mod.rs              the two new parse errors lower as unexpected tokens
    ├── semantics/
    │   ├── src/internal/checker/sharp.rs       is_undecided, never_written, and each refusal's words
    │   └── tests/sharp.rs                      the rows in the new words, and rows for forms no test covered
    └── syntax/
        ├── src/error.rs                        RequiredMethodInSharp, TraitUseInSharp, and `.=` names `+=`
        ├── src/parser/internal/class_like/     method.rs and trait_use.rs report them
        └── tests/sharp.rs                      the rows in the new words
Problem

patch-coverage found 22 lines of the checker's new refusals that no test
ran: an interface method without a return type, a parameter list on
`get`, an accessor of another name, `Iterable` without its type
argument, a modifier on a method and on a parameter, and arms that no
input reaches.

Solution

a_member_form_php_sharp_never_has_names_what_to_write runs each
reachable one. The arms no input reaches go: a modifier on a class and
on an interface method parses as an error or has its own arm, and
`never_written` matches `include`, `include_once`, `require`,
`require_once` and a type declared in a method by their patterns, so
no fallback arm and no `declared_type_name` remain. `private(set)` and
its siblings read their access level from the form as written.

php-sharp/sharp/mago/crates/semantics/
├── src/internal/checker/sharp.rs   never_written's arms
└── tests/sharp.rs                  a_member_form_php_sharp_never_has_names_what_to_write
…HP#'s words

Problem

#166's review found refusals whose advice is wrong or missing. `__get`,
`__invoke` and `__construct` were told to drop their underscores, which
gives a plain method nothing calls. `required` on a method said only the
constructor takes it, though a property does. `public(set)` named
`{ get; public set; }`, which the checker refuses. `eval` and `static $x`
named nothing to write, and `eval`'s help named `function eval()`, which
PHP can't declare. A member read or `new` in a constant value, an enum
case's `value` in a constant, a `List` constant and `virtual` on a class
said the form "is not part of PHP#", which says PHP# has no member
reads. The parse errors said "is PHP syntax", the trait `use` named no
trait, `[a, b] = …` named no PHP# form, the `parent` type named no class,
the header error named nothing to write, and the cast and `&` notes
explained PHP.

Solution

A `__` method name names what PHP# writes for PHP's job: `toString`,
the constructor or `with`, and a method PHP calls by itself is one PHP#
never calls, so the developer gives it a camelCase name and calls it.
Any other name loses its underscores when the rest is camelCase.

`required` goes on the constructor or a property. `public(set)` names
`{ get; set; }`. `eval` joins the removed constructs, and a `static`
local names a `private static` field.

In a constant value, a member read names the read, and anything else
the slice lacks names what it holds, as a call already did. A case's
`value` or `name` there, and a constant of any generic type, are not
supported yet. A modifier on a class names the class again.

Every parse error of PHP syntax reads as the checker's own refusals do,
"PHP# has no `.=`: append with `+=`.", and so do the analyzer's
`list[] = value` and `map[] = value`. The trait `use` names its traits.
`[a, b] = …` names `const [a, b] = …`, which unpacks a tuple. `parent`
names the base class when the header lists one name, and the names it
lists otherwise. The header error names what to list, `iterable` in a
constant names the types a constant holds, and the cast and `&` notes
say what PHP# does.

php-sharp/sharp/mago/crates/
├── analyzer/
│   ├── src/expression/assignment/array_assignment.rs   `list[]` and `map[]` in PHP#'s words
│   └── tests/sharp.rs                    the new wording, and a row that compiles each named form
├── semantics/
│   ├── src/internal/checker/sharp.rs     double_underscore_name, never_written, is_undecided,
│   │                                     parent_instead and the notes
│   └── tests/sharp.rs                    the new wording, and rows for each finding
├── sharp-bridge/tests/lower.rs           the new parse wording
└── syntax/
    ├── src/error.rs                      PhpSyntaxInSharp's messages, TraitUseInSharp's traits
    ├── src/parser/internal/class_like/trait_use.rs   names the traits it reports
    └── tests/sharp.rs                    the new wording
Problem

The review's keep probes found two forms PHP# has not decided that this
PR refused for good. `new Report()` in an attribute argument said "A
constant value can't hold `new Report()`", and `[Logged] public event
Noted(int id);` said "This construct is not part of PHP#." master says
both are not supported yet, and nothing decided otherwise.

Solution

In a constant value, a call and a member read name what a constant
holds, and every other expression the slice lacks is not supported yet,
as master has it. An event's attributes are not supported yet.

php-sharp/sharp/mago/crates/semantics/
├── src/internal/checker/sharp.rs   report_unsupported and is_undecided
└── tests/sharp.rs                  the two rows say not supported yet
Problem

An attribute on an interface, an interface method or a constant said
"This construct is not part of PHP#.", though PHP# writes attributes and
has not decided those places. master says not supported yet. Three
refusals also explained PHP: "PHP# writes `Object` for PHP's `object`.",
"PHP# writes `Self` for PHP's `static`." and "a `.sharp` file runs with
PHP's default settings".

Solution

Every attribute list the slice places nowhere is not supported yet. A
case in an interface, which neither PHP nor PHP# has, stays the one
form a test reports as no PHP# construct. The three refusals read
"PHP# has no `object`: write `Object`.", "PHP# has no `static` class
name: write `Self`." and "PHP# has no `declare(ticks=1)`: a `.sharp`
file takes no settings."

php-sharp/sharp/mago/crates/semantics/
├── src/internal/checker/sharp.rs   is_undecided and the three messages
└── tests/sharp.rs                  rows for each
…s name what PHP# writes

Problem

Six refusals named no PHP# form, or named a PHP one. `global`,
`compact()` and `extract()` said they are "not part of PHP#". `list()`
pointed at `const first = pair[0];` where PHP# unpacks a tuple. A `fn`
or `function` lambda read "PHP# writes a lambda as a bare arrow …"
whichever keyword the code wrote. A class attached as an attribute
that is no attribute class said to add PHP's `#[Attribute]`.

Solution

Each reads "PHP# has no `X`: …" with the form that compiles:

  PHP# has no `global`: pass the value in as a parameter.
  PHP# has no `compact()`: build the Map, as in `["name": name]`.
  PHP# has no `extract()`: read each value from the Map by its key, as in `map.get("name")`.
  PHP# has no `list`: write `const [a, b] = …`.
  PHP# has no `fn`: write the lambda as `(x) => x * 2`.

The lambda error carries the keyword the code wrote, `fn` or
`function`. In a `.sharp` file, a PHP# class that is no attribute class
reads "`Field` is no attribute class: mark it `[Attribute]`.", and a
plain PHP class, which its library marks, reads "attach an attribute
class instead". A `.php` file keeps upstream's wording. A row compiles
each named form.

php-sharp/sharp/mago/crates/
├── analyzer/
│   ├── src/statement/attributes/mod.rs     ClassNotMarkedAsAttribute in PHP#'s words
│   └── tests/sharp.rs                      the attribute rows and the compile row
├── semantics/
│   ├── src/internal/checker/sharp.rs       global, compact, extract and list
│   └── tests/sharp.rs                      their rows
└── syntax/
    ├── src/error.rs                        PhpLambdaInSharp carries its keyword
    ├── src/parser/internal/common.rs       passes the keyword
    └── tests/sharp.rs                      the lambda rows
…d beside the permanent refusals

Problem

#159, #165, #168, #170 and #171 landed on master. #159 gives attributes
to interfaces, events, constants, accessors and lambdas, #168 gives
every pattern type a test, and the collections work builds tuple and
`Iterable` constants. #166's refusals of those forms as "not supported
yet" are now refusals of code that compiles. `==` on an `Iterable` was
still "not supported yet", and a `.sharp` file the engine refused stayed
in PHP's included files, so a second `require_once` skipped it and a
later use said "Class not found".

Solution

The merge keeps master's attribute arms, its `as` arm and its
attribute-argument refusal, keeps `report_accessor` with #159's
observer-attribute arm and its `ACCESSORS` note, and drops the arms
master made unreachable: `is_undecided`'s attribute lists, pattern
types with no test and tuple constants.

`==` on an `Iterable`, or on a type parameter bound by a collection,
is a permanent error that names `toList()`: "`==` compares a `List`, a
`Map` or a `Set`, and an `Iterable` is none of them: compare
`a.toList() == b.toList()`." A search and a struct property say the
same.

A `.sharp` file the engine refuses leaves PHP's included files, so a
second `require_once` reports the same refusal.

Spec section 20's `case-set-field` states its result, `// true`, which
the spec tool now runs.

php-sharp/
├── Zend/tests/sharp/refusal_required_again.phpt     a refused file is required again
├── docs/spec.md                                      case-set-field gives true
├── ext/sharp/sharp.c                                 sharp_compile_file drops a refused file
└── sharp/mago/crates/
    ├── analyzer/
    │   ├── src/expression/binary/comparison.rs       `==` on an Iterable names toList()
    │   └── tests/sharp.rs                            its rows, and a row that compiles toList()
    ├── hir/src/lower/error/mod.rs                    both sides' error list
    └── semantics/
        ├── src/internal/checker/sharp.rs             is_undecided, report_accessor, the as arm
        └── tests/sharp.rs                            rows for what master builds
Problem

library_autoload_composer_container.phpt pinned the old behavior. Its
callback loads App\Greeting, whose app/Greeting.sharp the engine
refuses, then asks Sharp\Container for App\Greeting. The refused file
stayed in PHP's included files, so the container's load skipped it and
the row read the Error requireNative throws instead of the compile
error.

Solution

A refused file now leaves the included files, so the container's load
compiles it again, and the three container rows expect the same
CompileError the require rows give.

php-sharp/Zend/tests/sharp/
└── library_autoload_composer_container.phpt   the container rows expect CompileError
Problem

`new class implements Notifier { … }` said "This expression is not
supported yet in PHP#." Jordan decided on 10-18 that PHP# has no
anonymous class, so the refusal promised a feature that is not coming.

Solution

An anonymous class is a permanent error that names the class to
declare, with the base class and the interfaces the code names:
"PHP# has no class without a name: declare a class that implements
`Notifier` in its own file." With none, it says "declare a class in its
own file".

php-sharp/sharp/mago/crates/semantics/
├── src/internal/checker/sharp.rs   never_written names the class, is_undecided drops it
└── tests/sharp.rs                  a row per header, and the `internal` row
@heyJordanParker
heyJordanParker merged commit 85392d4 into master Oct 18, 2026
24 checks passed
heyJordanParker added a commit that referenced this pull request Oct 18, 2026
#166 kept "not supported yet" arms for the constant-value forms this
branch builds. Each form now has one arm, this branch's:

- is_undecided loses its arms for a case's `value` and `name` in a
  constant value, and for a constant typed as a function or a generic
  class. A constant takes any generic type, as `Class<Report>`, and its
  value decides what it holds.
- never_written loses its call-in-a-constant arm. A call there reports
  "A constant's value is known before the code runs, and `…` runs code".
- check_cast keeps #166's permanent refusals of `(unset)` and `(void)`,
  and drops its place, which nothing reads now.
- The semantics rows of those arms are gone, and the spec self-test's
  refusal example is `break 2`, a form PHP# has not decided.
@heyJordanParker
heyJordanParker deleted the fix/permanent-refusals 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