vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.54k stars 659 forks source link

False positive on `UnusedPsalmSuppress` #8082

Open RSickenberg opened 2 years ago

RSickenberg commented 2 years ago

Hello folks:

I got this error:

ERROR: UnusedPsalmSuppress - web/modules/custom/<redacted>/src/Plugin/Block/HeaderBlock.php:39:1 - This suppression is never used (see https://psalm.dev/207)
      ],
    ];

(The two last lines are red)

Here is the link to get the code: https://psalm.dev/r/70a9ffdd01

Psalm version: Psalm 4.22.0@fc2c6ab4d5fa5d644d8617089f012f3bb84b8703

Regards

psalm-github-bot[bot] commented 2 years ago

I found these snippets:

https://psalm.dev/r/70a9ffdd01 ```php getMenuTreeParameters('main'); $variables['menu_items'] = $this->loadMenuTree('main', $parameters); // Get the last item in active trail to generate a11y #main-content link. $variables['menu_items_active_trail'] = $this->getActiveTrail($parameters); // Get the first item in active trail to highlight proper 1st level link. $variables['menu_first_item_active_trail'] = end($parameters->activeTrail); return [ '#theme' => 'redacted_layout__header', '#variables' => $variables, '#cache' => [ 'contexts' => [ 'url', ], 'tags' => [ 'menu:main', ], ], ]; } } ``` ``` Psalm output (using commit a9775c6): ERROR: UndefinedClass - 14:27 - Class, interface or enum named Drupal\redacted_layout\Plugin\Block\MenuBlockBase does not exist ```
AndrolGenhald commented 2 years ago

I filled in the missing methods and tested on that version and it worked fine. Can you provide a reproduction repo that I can clone to reproduce the issue?

Also, could you try running with --no-cache? No clue if that's the issue here, but our cache system is unfortunately very unreliable at the moment :slightly_frowning_face:

psalm-github-bot[bot] commented 2 years ago

I found these snippets:

https://psalm.dev/r/9f433197e7 ```php */ public array $activeTrail = []; } class MenuBlockBase { public function getMenuTreeParameters(string $str): Parameters { return new Parameters(); } public function loadMenuTree(string $str, Parameters $params): string { return "foobar"; } public function getActiveTrail(Parameters $params): string { return "foobar"; } } /** * Provides a "Header" block. * * @Block( * id="redacted_layout_header_block", * admin_label="Header", * category="Redacted" * ) */ class HeaderBlock extends MenuBlockBase { /** * {@inheritdoc} */ public function build(?array $params = []): array { $variables = []; // Load main menu. $parameters = $this->getMenuTreeParameters("main"); $variables["menu_items"] = $this->loadMenuTree("main", $parameters); // Get the last item in active trail to generate a11y #main-content link. $variables["menu_items_active_trail"] = $this->getActiveTrail($parameters); // Get the first item in active trail to highlight proper 1st level link. $variables["menu_first_item_active_trail"] = end($parameters->activeTrail); return [ "#theme" => "redacted_layout__header", "#variables" => $variables, "#cache" => [ "contexts" => [ "url", ], "tags" => [ "menu:main", ], ], ]; } } } ``` ``` Psalm output (using commit a9775c6): No issues! ```
RSickenberg commented 2 years ago

Hello @AndrolGenhald,

Unfortunately, the issue still remains even with --no-cache and due to the complexity of the project, I can't make a reproduction repo. :(

boesing commented 2 years ago

I had these as well when working on my psalm plugin. Whenever psalm internal issues are thrown from a plugin, psalm does not properly interprete these issues when using psalm-suppress.

Can you probably disable some plugins to see if the issue disappears?