Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Novynn opened this issue Sep 25, 2024 · 1 comment
Open

Comments

@Novynn
Copy link

Novynn commented Sep 25, 2024

/** @var array<string, int|string|float|null|array> */
$class_constants = $reflected_class->getConstants();
foreach ($class_constants as $name => $value) {
$storage->constants[$name] = new ClassConstantStorage(
ClassLikeAnalyzer::getTypeFromValue($value),
new Union([ConstantTypeResolver::getLiteralTypeFromScalarValue($value)]),
ClassLikeAnalyzer::VISIBILITY_PUBLIC,
null,
);
}

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)
Copy link

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.

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

No branches or pull requests

1 participant