Commit 64e339b
Fix catch block scope for union throw types with direct match
When a method declares `@throws A|B` and a catch block catches `A`,
the check for direct explicit non-throw match was using
`$catchType->isSuperTypeOf($throwType)->yes()` which returns `maybe`
for union throw types (since the catch doesn't cover `B`).
This caused implicit throw points to be included unnecessarily,
leading to false "variable might not be defined" reports.
The fix decomposes union throw types and checks each member
individually, so `A` in `A|B` is recognized as a direct match
for `catch (A)`. Non-union types retain the original behavior,
preserving correctness for cases like `@throws RuntimeException`
caught as `PDOException`.
Fixes inconsistency between DbCommand5 and DbCommand6 test cases.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent a191a3b commit 64e339b
1 file changed
Lines changed: 7 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1896 | 1896 | | |
1897 | 1897 | | |
1898 | 1898 | | |
1899 | | - | |
1900 | | - | |
| 1899 | + | |
| 1900 | + | |
| 1901 | + | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
| 1905 | + | |
1901 | 1906 | | |
1902 | 1907 | | |
1903 | 1908 | | |
| |||
0 commit comments