pint icon indicating copy to clipboard operation
pint copied to clipboard

Braces bug since 1.19.0

Open Seb33300 opened this issue 10 months ago • 3 comments

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:

Image

For some reason, the issue seems to be caused by set();. If I replace set(); by se(); of sett();, pint pass successfully.

Seb33300 avatar Feb 27 '25 03:02 Seb33300

Just created that PR to reproduce the issue: https://github.com/laravel/pint/pull/353

Seb33300 avatar Feb 27 '25 03:02 Seb33300

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 short set hooks. set => $value will be expanded to set { $this->propertyName = $value; }. This requires the propertyName attribute 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.

Seb33300 avatar Feb 27 '25 04:02 Seb33300

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

Seb33300 avatar Mar 04 '25 03:03 Seb33300