Psalm is not able to infer types from doc blocks of Google\Protobuf with 'protobuf' extension installed
#8 281 ouverte le 18 juil. 2022
Métriques du dépôt
- Stars
- (5 369 stars)
- Métriques de merge PR
- (Merge moyen 3j 12h) (5 PRs mergées en 30 j)
Description
Hi,
I have the protobuf extension installed in container in which I run Psalm, this causes psalm to not be able to infer types from Google\Protobuf classes, resulting in MixedAssignment and other errors, please see example below:
ERROR: MixedAssignment - index.php:3:1 - Unable to determine the type that $t is being assigned to (see https://psalm.dev/032)
$t = (new \Google\Protobuf\Timestamp())->setSeconds(0)->setNanos(0);
If I remove the protobuf extension, Psalm no longer reports those errors.
I've created a repository with reproducible example here: https://github.com/benkelukas/psalm-google-protobuf-issue
For now, I'm using container without protobuf for Psalm, but somebody might not have the options, so wanted to leave this here in case somebody else has this weird problem.
I've done some digging as well, and from my very much limited knowledge of Psalm, it seems that with the protobuf extension, the Google\Protobuf classes are not located via composer, but analyzed using reflection instead, and these classes do not have return types specified in actual code, but rather via annotations, so maybe that is what is breaking this? If you compare output of --debug-by-line with the extension and without it is different when processing the Google\Protobuf classes.
Some info on my environment:
- Psalm version: 4.24.0
- PHP: 8.1.1