vimeo / psalm

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

Ignore finally block in try catch #11170

Open bless-rng opened 1 week ago

bless-rng commented 1 week ago

When i use finally where i setup variable as not nullable - psalm still null possible error

<?php

function test(int $a, int $b): int { try { $c = (int)($a / $b); } catch(Throwable $t) { $c = null; } finally { $c = 1; } return $c; }

psalm-github-bot[bot] commented 1 week ago

Hey @bless-rng, can you reproduce the issue on https://psalm.dev? These will be used as phpunit tests when implementing the feature or fixing this bug.

bless-rng commented 1 week ago

Hey @bless-rng, can you reproduce the issue on https://psalm.dev? These will be used as phpunit tests when implementing the feature or fixing this bug.

https://psalm.dev/r/a8595a9c94

psalm-github-bot[bot] commented 1 week ago

I found these snippets:

https://psalm.dev/r/a8595a9c94 ```php
bless-rng commented 5 days ago

Also i found more cases. Combine try/catch with switch case

  1. Try catch with switch case - https://psalm.dev/r/a08800bdf5
  2. Proof that try catch is work correct - https://psalm.dev/r/51ce75c690
  3. Try catch with if else (replace switch case variants) - https://psalm.dev/r/c63ea0be0f
psalm-github-bot[bot] commented 5 days ago

I found these snippets:

https://psalm.dev/r/a08800bdf5 ```php
https://psalm.dev/r/51ce75c690 ```php
https://psalm.dev/r/c63ea0be0f ```php