vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.57k stars 660 forks source link

Enum class being passed to Reflection::registerClass causes psalm to crash #11102

Open Novynn opened 1 month ago

Novynn commented 1 month ago

https://github.com/vimeo/psalm/blob/d747f6500b38ac4f7dfc5edbcae6e4b637d7add0/src/Psalm/Internal/Codebase/Reflection.php#L163-L173

This section assumes that the constant value is a scalar, and so makes no attempts to handle when it is not. Enum classes have object constants, so the InvalidArgumentException is triggered.

Target PHP version: 8.2 (inferred from current PHP version).
Scanning files...
Uncaught InvalidArgumentException: $value must be a scalar. in /data/poe_packages/trunk/development/1/webserver/Website/application/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/ConstantTypeResolver.php:409
Stack trace:
#0 /data/poe_packages/trunk/development/1/webserver/Website/application/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Reflection.php(169): Psalm\Internal\Codebase\ConstantTypeResolver::getLiteralTypeFromScalarValue(Object(Grindb\Account\Language))
#1 /data/poe_packages/trunk/development/1/webserver/Website/application/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Scanner.php(486): Psalm\Internal\Codebase\Reflection->registerClass(Object(ReflectionClass))
#2 /data/poe_packages/trunk/development/1/webserver/Website/application/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Scanner.php(284): Psalm\Internal\Codebase\Scanner->convertClassesToFilePaths(Object(Psalm\Internal\Codebase\ClassLikes))
#3 /data/poe_packages/trunk/development/1/webserver/Website/application/vendor/vimeo/psalm/src/Psalm/Codebase.php(505): Psalm\Internal\Codebase\Scanner->scanFiles(Object(Psalm\Internal\Codebase\ClassLikes), 1)
#4 /data/poe_packages/trunk/development/1/webserver/Website/application/vendor/vimeo/psalm/src/Psalm/Config.php(2443): Psalm\Codebase->scanFiles()
#5 /data/poe_packages/trunk/development/1/webserver/Website/application/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(529): Psalm\Config->visitStubFiles(Object(Psalm\Codebase), Object(Psalm\Progress\DefaultProgress))
#6 /data/poe_packages/trunk/development/1/webserver/Website/application/vendor/vimeo/psalm/src/Psalm/Internal/Cli/Psalm.php(379): Psalm\Internal\Analyzer\ProjectAnalyzer->check('/data/poe_packa...', true)
#7 /data/poe_packages/trunk/development/1/webserver/Website/application/vendor/vimeo/psalm/psalm(9): Psalm\Internal\Cli\Psalm::run(Array)
#8 /data/poe_packages/trunk/development/1/webserver/Website/application/vendor/bin/psalm(119): include('/data/poe_packa...')
#9 {main}
(Psalm 5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0 crashed due to an uncaught Throwable)
psalm-github-bot[bot] commented 1 month ago

Hey @Novynn, can you reproduce the issue on https://psalm.dev? These will be used as phpunit tests when implementing the feature or fixing this bug.