Commit ff42ae6
Do not let
- When the specific `method_exists` handling in `ImpossibleCheckTypeHelper` cannot
determine the result (no concrete class names, no GenericClassStringType), it falls
through to the general type specifier logic
- The general logic uses `HasMethodType::isSuperTypeOf()` which calls `hasMethod()` on
the argument type; for `object&T` where T is a TemplateMixedType, this returns Yes
(inherited from MixedType), causing a false positive "will always evaluate to true"
- Add early `return null` when `$objectType->hasTemplateOrLateResolvableType()` is true,
preventing the general logic from running on types where method existence is uncertain
- Verified analogous cases: `property_exists` is not affected (its type specifying
extension returns empty SpecifiedTypes for non-native properties); `is_callable` is
not affected; `class-string<T>` template bounds are correctly handled by the existing
GenericClassStringType blockmethod_exists() check fall through to general logic when object type contains template types1 parent 0beee48 commit ff42ae6
3 files changed
Lines changed: 28 additions & 0 deletions
File tree
- src/Rules/Comparison
- tests/PHPStan/Rules/Comparison
- data
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
245 | 249 | | |
246 | 250 | | |
247 | 251 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1224 | 1224 | | |
1225 | 1225 | | |
1226 | 1226 | | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
1227 | 1233 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
0 commit comments