Repository navigation
fix: every form PHP# never writes fails as a typo does - #176
Merged
Merged
Conversation
Jordan's ruling of 10-18: unsupported syntax errors out just the same as
`public asdf#($@`. A per-form message that names the form or its
replacement says PHP# recognizes it, so the checker now gives each such
form the parser's own typo error.
- ParseError::unexpected_in_sharp lexes the first token at an offset as
a PHP# file reads it and returns the parser's UnexpectedToken error:
code `parse`, "Parse error encountered during parsing", at the token.
- The checker reports it through report_unexpected for `|>`, an open
argument (`?` or `...`) in a call, `break 2`, `goto` and labels,
`elseif`, `trait`, `extends`, `implements`, `public(set)`, `<>`, `&`,
`&get`, `static $x`, heredocs, `clone`, `new class`, `include`,
`require`, `new $class()`, `new Report;`, `[, x]`, `this.{"run"}`,
`echo` and `print` statements, `declare`, `global`, `compact()`,
`extract()`, top-level functions, `$` variables, superglobals, magic
constants, `__` names, `self`, `static`, PHP's type names, `?:`,
`instanceof`, `and`, `or`, `xor`, `switch`, `@` and PHP's other casts.
- `eval`, `isset`, `empty`, `unset`, `array`, `list`, `die` and the call
forms of `echo` and `print` are plain PHP# names, so they fail as any
unknown name does, in the analyzer.
- never_written keeps only the rules a PHP# form breaks at its place and
is renamed broken_rule. REMOVED_CONSTRUCTS, removed, report_removed,
report_not_supported, report_first_class_callable, report_php_self,
report_php_static, report_superglobal, report_magic_constant,
standard_class, double_underscore_name and parent_instead are gone.
sharp/mago/crates/
├── syntax/src/error.rs ParseError::unexpected_in_sharp
└── semantics/
├── src/internal/checker/sharp.rs report_unexpected, broken_rule
└── tests/sharp.rs rows expect the typo error
A form PHP# never writes fails as a typo does, so no message may name
it. mago's own checks still named the PHP forms the PHP# checker
refuses: "The pipe operator (`|>`) is not available…", "Partial function
application is only available…", the `unset` and `void` cast messages,
"Cloning with properties…" and "Undefined `goto` label". A PHP version
gates PHP's syntax, never PHP#'s, so the walk skips those checks in a
`.sharp` file, as it already skips `declare`. A plain PHP file keeps
every one.
ResolvedNames::shadows_default_class fed only the helps the checker no
longer gives, so it is gone with the set the walker filled for it.
sharp/mago/crates/
├── semantics/
│ ├── src/internal/mod.rs version and goto checks skip .sharp
│ └── tests/sharp.rs a row per check, the PHP twin keeps them
└── names/
├── src/lib.rs shadows_default_class removed
├── src/internal/walker.rs stops recording shadowed classes
└── tests/binder.rs its test removed
The parser named each PHP, C# and TypeScript form it found in a `.sharp`
file and the PHP# form to write instead. Under Jordan's ruling of 10-18
each is unsupported syntax, so each now records the parser's own
UnexpectedToken error, at the token it already pointed to, and still
parses on as before.
- Parser::report_unexpected_in_sharp records it, read from the source
as ParseError::unexpected_in_sharp reads it for the checker.
- PhpSyntaxInSharp (`->`, `?->`, `?Type`, `::`, `.=`, `function`, `var`,
`$`, `use`, `foreach`, `=>` in a map, `<?php`, `<?`, `<?=`, `?>`,
`#[`), ClassNameConstantInSharp, QualifiedNameInSharp,
NamedReachInSharp, ForInInSharp, TraitUseInSharp, PhpLambdaInSharp,
PartialTypeInSharp, ClassCastInSharp and
TypeParameterAttributesInSharp are gone, with their messages and
expect_php_lambda_keyword, which now duplicated expect_php_keyword.
- Jordan's answer of 10-18: an attribute always describes a
declaration, so `[return: X]` fails as a typo does at `return`.
sharp/mago/crates/
├── syntax/
│ ├── src/error.rs ten variants removed
│ ├── src/parser/mod.rs Parser keeps its source
│ ├── src/parser/internal/common.rs report_unexpected_in_sharp
│ ├── src/parser/internal/*.rs each site records the typo
│ └── tests/sharp.rs rows expect the typo error
├── hir/src/lower/error/mod.rs the removed variants
└── semantics/
├── src/internal/checker/sharp.rs `return:` target
└── tests/sharp.rs its rows
…o does PHP's append is no PHP# syntax, so on a `List` or a `Map` the analyzer now reports the parser's own UnexpectedToken error at the `[`, in place of the two messages that named `add` and `map[key] = value`. A `Set` keeps "has no index", a rule on PHP# indexing. The rows of other suites that quoted a refusal this branch removed move to the typo error: - the analyzer rows of the parser's refusals and of `use` in a class - sharp-bridge lower.rs: `->`, `echo` and `\null` rows; the not-supported-yet row now writes an intersection type, since `break 2` fails as a typo does - tests/sharp.rs: refusals report code `parse`, not `semantics` - orchestrator compile.rs: the shadowed-class help test keeps only what still holds, that the aliased imports compile sharp/mago/ ├── crates/analyzer/src/expression/assignment/array_assignment.rs ├── crates/analyzer/tests/sharp.rs ├── crates/sharp-bridge/tests/lower.rs ├── crates/orchestrator/src/service/incremental_analysis/compile.rs ├── crates/semantics/tests/sharp.rs a doc line ├── crates/syntax/src/parser/internal/modifier.rs a doc line ├── tests/sharp.rs └── tests/support/sharp_words.rs a doc example
Each now fails as a typo does, so its line expects the parse error, with
no advice. Section 1 states Jordan's answer of 10-18: an attribute
always describes a declaration, so `[return: X]` and an attribute on a
type parameter are parse errors. The class with an attributed type
parameter sits on one line, since sharp/bin/spec checks a parse error
line by blanking it.
- §1: `[return: Searchable]`, `Shelf<[Searchable] TItem>`
- §8: `echo` and `print`
- §23: `@` before a value
- §24: `(array)` and `(object)`
- §27: `__FILE__`
- §29: `_SERVER`
compile_command.phpt expects the typo error for `echo` in Wrong.sharp
and Order.sharp.
env TEST_MAGO_EXECUTABLE=<debug mago> php sharp/bin/spec
reports no compile-time problem. The examples it lists all stop on a
run, since the PHP on this machine has no PHP# engine. CI's LINUX job
runs them on the built engine.
Each line that quoted a message this branch removed now says the form fails as a typo does, or, for `die`, that it is a plain name. Messages that stay, such as `never`'s, `Closure`'s and the casing ones, are kept. - slices 06, 08, 12, 14, 21, 23, 24, 25, 27 and 29 - decisions 002, 037, 038 and 052: their examples say `// parse error` - decision 034 gains a superseded-in-part note for Jordan's ruling of 10-18, and 080 stops saying a bare `die` names its replacement - the checker's contract doc names the three outcomes of a node outside the slice: not supported yet, a broken PHP# rule, or the typo error
`public void __construct() { }` in a `.sharp` file gave the typo error
and mago's own "Magic method `Report.__construct` cannot have a return
type hint.", which names the PHP form. A PHP# method name never starts
with `__`, so the magic method checks of a class and of an enum skip a
`.sharp` file, as the version and `goto` label checks do.
Test names and docs that still promised a message naming the
replacement now say the form fails as a typo does. The two superglobal
tests whose forms had their own messages, `_ENV` and `$argv`, fold into
the superglobal test, since every superglobal now gives one error.
`this.format(cents: ?)` runs the named placeholder arm of `unexpected_part`, the one line patch-coverage found no test for.
Team-lead's Queue 7 named three arms that still recognized a form PHP# never writes, and one that still said it was not supported. - PHP's colon-delimited body, `if (…): … endif;` and the `while` and `for` forms, got the braces rule with a rewritten block as its fix. It now fails as a typo does, at its `:`. The braceless body, `if (x) return 1;`, a C#, Java and TypeScript form, keeps the rule. - `[, a] = [1, 2];` got "`[, a]` can't be written to.". A skipped element is no PHP# syntax anywhere, so the target fails as a typo does at its `,`, as `const missing = [, extra];` already did. - `tags[] = 1` on a `Set` got "A `Set<int>` has no index.". An append fails as a typo does on every collection, from one arm, and is its only report. - An attribute target after the first attribute, as in `[Cached, method: Logged]`, fails as a typo does at the target's name. `LateAttributeTargetInSharp` and its message are gone. sharp/mago/crates/ ├── semantics/src/internal/checker/sharp.rs colon bodies, `[, a]` ├── semantics/tests/sharp.rs their rows ├── syntax/src/error.rs LateAttributeTargetInSharp gone ├── syntax/src/parser/internal/attribute.rs the late target ├── syntax/tests/sharp.rs its row, `foreach:` ├── hir/src/lower/error/mod.rs the removed variant ├── analyzer/src/expression/assignment/array_assignment.rs every append └── analyzer/tests/sharp.rs the `Set` row
#173 makes a constant's value any expression built from constants, and reports one that runs code with report_call_in_constant. This branch reports every form outside the grammar as a typo. The conflicts in the checker resolve to both: - check_cast and check_conditional take #173's signatures, with this branch's typo error for every cast but `(int)`, `(float)` and `(string)`, and for `?:`. - report_unsupported keeps unexpected_part, then reports any other node in a constant value through report_call_in_constant. That function now takes a span, so `this` in a constant value, a constant access node, says it runs code instead of failing as a typo. - broken_rule drops both sides' arms: #173's call and property read in a constant, and this branch's PHP forms. - an_undecided_form_is_not_supported_yet keeps the intersection type, the one form left there.
#173 changed the `refusal` example to `while (true) { break 2; }`, but `break 2` now fails as a typo does, so the line no longer shows a "not supported yet" refusal. An intersection type is still not supported yet, so `public void pair(Order & Line both) { }` shows it.
- `Closure` gets what an unknown class name gets. `run(Closure f)` and `import Closure;` give the errors `Closur` gives. The checker's import error and the analyzer's "PHP# has no `Closure`" are gone, and is_php_closure keeps PHP's class out of a `.sharp` file's import check and out of the "is not imported" search. - `die`, `compact`, `extract` and `clone` are REPLACEMENTS rows of a new kind, Replacement::Removed, so a bare call, a `global.` call and a read as a value each get one `wrapped-function` error. The bare `die(…)` no longer says to write `global.die(…)`, `global.clone(this)` no longer compiles, and is_compact_or_extract and its parse error are gone. The `die` branch of analyze_namespace_function_call is gone too. - An unsupported declaration fails at its keyword, after its attributes and modifiers, as `trait` in `[Deprecated] trait Old` and in `public trait Tagged`. - A parse error drops the analyzer issues on its line, as a semantic error already does, so `: base(row)` and `: parent(row)` get the parser's rule alone, without `missing-super-call`. - `OBJECT` gets "PHP# writes `Object`.", as `ANY` gets its case message. PHP's lowercase `object` still fails as a typo does. - A `.sharp` file is checked as PHP 8.5, the version the bridge lowers to, whatever `php-version` says, so it gets none of mago's version checks, as "Enums are only available in PHP 8.1 and above." under 8.0. The clone-with gate this made redundant is gone. sharp/mago/ ├── crates/analyzer/src/expression/call/function_call.rs Removed rows ├── crates/analyzer/src/resolver/class_name.rs Closure ├── crates/analyzer/src/resolver/property.rs compact, extract ├── crates/analyzer/src/statement/use_statement.rs Closure import ├── crates/analyzer/src/utils/names.rs is_php_closure ├── crates/orchestrator/src/service/issue_reconciliation.rs parse errors ├── crates/semantics/src/lib.rs PHP 8.5 ├── crates/semantics/src/internal/checker/sharp.rs keyword, OBJECT └── tests, docs/spec.md and the functions-as-values slice
heyJordanParker
added a commit
that referenced
this pull request
Oct 18, 2026
… members
is_undecided keeps the branch's one interface arm, a property in another form
than { get; }, { get; set; } and => expr;, beside #176's list, which moved break
with a level, |> and a partial application to unexpected_part.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Jordan's ruling of 10-18: every form PHP# never writes fails exactly as a typo does. A
.sharpfile that writespublic asdf#($@gets mago's own parse error,error[parse]: Parse error encountered during parsing, at the first token PHP# has no place for. Every PHP, C# and TypeScript form outside the PHP# grammar now gets that same error at its first such token, with no message that recognizes the form or names a replacement. A PHP# form that breaks a rule of its place keeps its own message.What changes for a user
->,?->,?Type,::(Order::classincluded),.=,function,fn,var,$,use(an import and a trait in a class),foreach,=>in a map literal,<?php,<?,<?=,?>,#[, a\name,internal(App.Tenant),for (x in y),partial, a class cast as(Admin) user, an attribute on a type parameter, and an attribute target after the first attribute, as in[Cached, method: Logged].|>,?as an open argument,break 2, a class without a name,global,gotoand labels,include,require,static $x,clone,new $class(),new Report;,elseif,extends,[, x]as a value and as a write target,this.{"run"}, a__method name, superglobals, magic constants and__Something__names, casts other than(int),(float)and(string),object,mixed,array,callable,true,false,parent, lowercaseiterable,declare,echo,print,switch,and,or,xor,?:,<>,&,[return: X], and PHP's colon-delimited bodies, asif (…): … endif;.traitin[Deprecated] public trait Audit.eval,isset,empty,unset,array,list, a baredieand the call forms ofechoandprintare names in PHP#, so a call of one is an unknown function.die,compact,extractandcloneget onewrapped-functionerror, called bare, called throughglobalor read as a value.dienamesconsole.writeErrorandprocess.exit,compactandextractsay PHP# code reads and writes a local only by its name, andclonenameswith.Closure:run(Closure f)andimport Closure;get exactly whatClosurgets, andClosurenever names PHP's class in a.sharpfile.x[] = valueon aList, aMapor aSet.: base(row)and: parent(row)get the parser's rule withoutmissing-super-call..sharpfile: a.sharpfile is checked as the PHP 8.5 that PHP# lowers to, whateverphp-versionsays, so it gets none of mago's version errors, as "Enums are only available in PHP 8.1 and above." under 8.0. mago'sgotolabel check skips.sharpfiles too.What stays
Self.TABLEandnew TItem.fromJson(…).Untyped*InSharp,MiscasedKeywordInSharp,RequiredMethodInSharp,: base(…), a braceless body, and a type written in another case, asINT,ANYandOBJECT.Deleted
REMOVED_CONSTRUCTSand every per-form refusal in the checker, elevenParseErrorvariants with their messages, the checker's and the analyzer'sClosureerrors,is_compact_or_extract, thediebranch of the analyzer'sglobal.calls, andResolvedNames::shadows_default_class.Docs
docs/spec.md's lines on these forms say
// parse errorwith no advice, and section 1 states that an attribute always describes a declaration. The slices and decisions stop quoting the removed messages.