Skip to content

Blink: fix NoUnneededControlParentheses on clone, and ConstantCase on names - #289

Merged
TomasVotruba merged 4 commits into
ecsphp:mainfrom
GErpeldinger:blink-broken-code
Nov 4, 2026
Merged

TomasVotruba merged 4 commits into
ecsphp:mainfrom
GErpeldinger:blink-broken-code

Conversation

@GErpeldinger

@GErpeldinger GErpeldinger commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Blink breaks this code. The PHP engine does not.

  • NoUnneededControlParentheses: clone ($a, ['x' => 1]) and clone(...) became a parse error, and clone ($a ?: $b) lost its meaning.
  • ConstantCase: const NULL = 1; became const null = 1;, so self::NULL failed at runtime.

Each fix commit follows a commit of failing tests, with expected output from the PHP engine.

One difference on purpose: after ?, the parentheses of anything but a plain variable only come off before :. PHP-CS-Fixer's output is a parse error for $f ? clone (new Foo)->bar : 1 and has another meaning for $f ? clone ($o->b)() : 1. A few harmless shapes such as $f ? clone ($o->b)->c : 1 keep them too.

🤖 Generated with Claude Code

The expected output of the tables comes from the PHP engine. The fix follows.
…nstantCase

clone was handled like return, so "clone ($a, [...])" became a parse error and
"clone ($a ?: $b)" lost its meaning. Follow PHP-CS-Fixer's isWrappedCloneArgument.
Different on purpose: after "?", the pair comes off only directly before ":", because
PHP-CS-Fixer's output for "$f ? clone (new Foo)->bar : 1" is a parse error.

ConstantCase changed every name that looks like true, false or null, so "const NULL"
became "const null" and "self::NULL" failed at runtime. Follow PHP-CS-Fixer's checks.
@GErpeldinger

Copy link
Copy Markdown
Contributor Author

CI here waits for a maintainer's approval, so I ran it on my fork. With the test commit alone, Blink Tests fails on Linux and Windows: https://github.com/GErpeldinger/ecs-src/actions/runs/41886939594. The fix is now pushed.

@GErpeldinger GErpeldinger changed the title Blink: fix two rules that break valid code Blink: fix NoUnneededControlParentheses on clone, and ConstantCase on names Nov 4, 2026
PHP-CS-Fixer removes these parentheses and the result is right, so blink should too.
The expected output comes from the PHP engine. The fix follows.
"$f ? clone ($a)->b : 1" keeps its meaning without them, so follow PHP-CS-Fixer there.
Other operands still keep them before anything but ":", where its output breaks.
@GErpeldinger

Copy link
Copy Markdown
Contributor Author

I added two commits so a plain variable after ? matches PHP-CS-Fixer, for example $f ? clone ($a)->b : 1. Failing tests alone, on my fork: https://github.com/GErpeldinger/ecs-src/actions/runs/41897593950. The fix is now pushed.

@TomasVotruba
TomasVotruba merged commit 058a68b into ecsphp:main Nov 4, 2026
21 checks passed
@TomasVotruba

Copy link
Copy Markdown
Member

LGTM, Thank you 👍

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.

2 participants