vimeo/psalm

Psalm is not able to infer types from doc blocks of Google\Protobuf with 'protobuf' extension installed

オープン

#8,281 opened on 2022/07/18

 (5 件のコメント) (0 件のリアクション) (0 人の担当者)PHP (668 件のフォーク)batch import
Help wantedeasy problemsgood first issueinternal stubs/callmap

Repository metrics

Stars
 (5,369 個のスター)
PR merge metrics
 (PR metrics pending)

説明

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

コントリビューターガイド