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

Psalm crash when parsing a PHPDoc tag that looks like a number #11217

Open
jlewisizone opened this issue Jan 29, 2025 · 1 comment
Open

Psalm crash when parsing a PHPDoc tag that looks like a number #11217

jlewisizone opened this issue Jan 29, 2025 · 1 comment

Comments

@jlewisizone
Copy link

The following code will cause Psalm to crash:

<?php
/** @1 */
<?php
/**
 * @1
 */
<?php
/** @1.3 */

The following will not crash Psalm

<?php
/** @1x */

This can be replicated on the Psalm website: https://psalm.dev/r/d5db1ec4ea

Full stacktrace below


Uncaught TypeError: str_starts_with(): Argument #1 ($haystack) must be of type string, int given in C:\redacted\vendor\vimeo\psalm\src\Psalm\DocComment.php:57
Stack trace:
#0 C:\redacted\vendor\vimeo\psalm\src\Psalm\DocComment.php(57): str_starts_with(1, 'psalm-')
#1 C:\redacted\vendor\vimeo\psalm\src\Psalm\Internal\PhpVisitor\Reflector\ClassLikeNodeScanner.php(1897): Psalm\DocComment::parsePreservingLength(Object(PhpParser\Comment\Doc))
#2 C:\redacted\vendor\vimeo\psalm\src\Psalm\Internal\PhpVisitor\ReflectorVisitor.php(110): Psalm\Internal\PhpVisitor\Reflector\ClassLikeNodeScanner::getTypeAliasesFromComment(Object(PhpParser\Comment\Doc), Object(Psalm\Aliases), Array, NULL)
#3 C:\redacted\vendor\nikic\php-parser\lib\PhpParser\NodeTraverser.php(196): Psalm\Internal\PhpVisitor\ReflectorVisitor->enterNode(Object(PhpParser\Node\Stmt\Nop))
#4 C:\redacted\vendor\nikic\php-parser\lib\PhpParser\NodeTraverser.php(76): PhpParser\NodeTraverser->traverseArray(Array)
#5 C:\redacted\vendor\vimeo\psalm\src\Psalm\Internal\Scanner\FileScanner.php(72): PhpParser\NodeTraverser->traverse(Array)
#6 C:\redacted\vendor\vimeo\psalm\src\Psalm\Internal\Codebase\Scanner.php(535): Psalm\Internal\Scanner\FileScanner->scan(Object(Psalm\Codebase), Object(Psalm\Storage\FileStorage), false, Object(Psalm\Progress\DefaultProgress))
#7 C:\redacted\vendor\vimeo\psalm\src\Psalm\Internal\Codebase\Scanner.php(763): Psalm\Internal\Codebase\Scanner->scanFile('C:\\redacted\\...', Array, true)
#8 C:\redacted\vendor\vimeo\psalm\src\Psalm\Internal\Codebase\Scanner.php(409): Psalm\Internal\Codebase\Scanner->scanAPath(0, 'C:\\redacted\\...')
#9 C:\redacted\vendor\vimeo\psalm\src\Psalm\Internal\Codebase\Scanner.php(261): Psalm\Internal\Codebase\Scanner->scanFilePaths(1)
#10 C:\redacted\vendor\vimeo\psalm\src\Psalm\Codebase.php(436): Psalm\Internal\Codebase\Scanner->scanFiles(Object(Psalm\Internal\Codebase\ClassLikes), 1)
#11 C:\redacted\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\ProjectAnalyzer.php(1042): Psalm\Codebase->scanFiles(1)
#12 C:\redacted\vendor\vimeo\psalm\src\Psalm\Internal\Cli\Psalm.php(385): Psalm\Internal\Analyzer\ProjectAnalyzer->checkPaths(Array)
#13 C:\redacted\vendor\vimeo\psalm\psalm(9): Psalm\Internal\Cli\Psalm::run(Array)
#14 C:\redacted\vendor\bin\psalm(119): include('C:\\redacted\\...')
#15 {main}
(Psalm dev-master@a17fdd709d1322edc47e8fa53c18b1d94ce8bdd8 crashed due to an uncaught Throwable)

Copy link

I found these snippets:

https://psalm.dev/r/d5db1ec4ea
<?php
/** @1 */
Psalm encountered an internal error:

/vendor/vimeo/psalm/src/Psalm/DocComment.php: str_starts_with(): Argument #1 ($haystack) must be of type string, int given

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants