Braces bug since 1.19.0
Pint Version
1.19.0+
PHP Version
8.4
Description
Starting version 1.19.0 of Laravel Pint, I am facing a very strange bug where Laravel Pint detects false positive issue with braces.
I cannot reproduce the issue on version 1.18.3.
Steps To Reproduce
This issue occurs only with PHP 8.4. Not on PHP 8.3
The minimum reproducer I found:
<?php
if (false) {
set();
}
Result:
For some reason, the issue seems to be caused by set();.
If I replace set(); by se(); of sett();, pint pass successfully.
Just created that PR to reproduce the issue: https://github.com/laravel/pint/pull/353
I suspect nikic/php-parser to be the root cause of that issue.
It was upgraded to 5.4.0 in Pint 1.19.0: https://github.com/laravel/pint/commit/2128bf584f5bfe9dc303e524dc75674e0cf7ce63
And in the changelog I can find something related to set:
https://github.com/nikic/PHP-Parser/releases/tag/v5.4.0
PropertyHook::getStmts()now correctly desugars shortsethooks.set => $valuewill be expanded toset { $this->propertyName = $value; }. This requires thepropertyNameattribute on the hook to be set, which is now also set by the parser. If the attribute is not set,getStmts()will throw an error for short set hooks, as it is not possible to produce a correct desugaring.
The issue may come from one of those package upgraded between Laravel Pint 1.18.3 and 1.19.0:
"name": "larastan/larastan",
"version": "v2.9.11",
"version": "v2.9.12",
"name": "phpstan/phpstan",
"version": "1.12.11",
"version": "1.12.13",
"name": "nikic/php-parser",
"version": "v5.3.1",
"version": "v5.4.0",
"name": "friendsofphp/php-cs-fixer",
"version": "v3.65.0",
"version": "v3.66.0",
Maintainer of nikic/php-parser said his changes are unrelated: https://github.com/nikic/PHP-Parser/issues/1072