-
-
Notifications
You must be signed in to change notification settings - Fork 946
Description
Bug report
Some bad code in my codebase is triggering this internal error. Normally I wouldn't report this since it's 100% my code's fault, but I think I found the cause. The exception name ShouldNotHappenException also encouraged me to look further into it. This happens at level 0.
Code snippet that reproduces the problem
This is proprietary code, so I can't share the exact code that's triggering this error, but I managed to replicate it in the playground: https://phpstan.org/r/02269ca4-cad0-486f-bf84-f19ea0a17dd9
Changing @param number $someInt to '@param Number $someInt' does not trigger the internal error, and will correctly report PHPDoc tag @param for parameter $someInt with type Number is incompatible with native type int. at level 2. I believe the issue is related to case-sensitivity. Not sure this matter, but the class Number is being declared by 3rd party code outside of composer, and it's in the global namespace.
Expected output
PHPStan should report this as an issue.
Stack trace
Fatal error: Uncaught PHPStan\ShouldNotHappenException: Type alias number already exists as a class. in phar:///composer/vendor/phpstan/phpstan/phpstan/src/PhpDoc/TypeAlias/TypeAliasesTypeNodeResolverExtension.php:48
Stack trace:
#0 phar:///composer/vendor/phpstan/phpstan/phpstan/src/PhpDoc/TypeNodeResolver.php(78): PHPStan\PhpDoc\TypeAlias\TypeAliasesTypeNodeResolverExtension->resolve(Object(PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode), Object(PHPStan\Analyser\NameScope))
#1 phar:///composer/vendor/phpstan/phpstan/phpstan/src/PhpDoc/PhpDocNodeResolver.php(212): PHPStan\PhpDoc\TypeNodeResolver->resolve(Object(PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode), Object(PHPStan\Analyser\NameScope))
#2 phar:///composer/vendor/phpstan/phpstan/phpstan/src/PhpDoc/ResolvedPhpDocBlock.php(261): PHPStan\PhpDoc\PhpDocNodeResolver->resolveParamTags(Object(PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode), Object(PHPStan\Analyser\NameScope))
#3 phar:///composer/vendor/phpstan/phpstan/phpstan/src/PhpDoc/ResolvedPhpDocBlock.php(133): PHPS in phar:///composer/vendor/phpstan/phpstan/phpstan/src/PhpDoc/TypeAlias/TypeAliasesTypeNodeResolverExtension.php on line 48