Fix phpstan/phpstan#13566: False positive staticMethod.impossibleType#5121
Conversation
ad8821e to
0eb267b
Compare
src/Analyser/TypeSpecifier.php
Outdated
| $parameterExpr instanceof Node\Scalar | ||
| || ($parameterExpr instanceof ConstFetch && in_array(strtolower($parameterExpr->name->toString()), ['true', 'false', 'null'], true)) |
There was a problem hiding this comment.
I had to hardcode this literal-value ast-expressions to differentiate real literal-values from infered types. otherwise existing tests started to fail, because we e.g. still want
$foo = null
assertNotNull($foo);to error with "is always false".
|
This pull request has been marked as ready for review. |
VincentLanglet
left a comment
There was a problem hiding this comment.
It ends up really differently form the initial fix
db849fa
^^'
ohh yeah.. I had multiple tries and different patches until I finally hopefully understood the problem good enough to come up with a proper fix |
8406cc6 to
3d44fe9
Compare
… for conditional return type with void/never - Fixed ImpossibleCheckTypeHelper to skip impossible check when rootExpr is a call argument in null (void) context - The conditional return type ($exit is true ? never : void) describes behavioral control flow, not a type check - Added regression test in tests/PHPStan/Rules/Comparison/data/bug-13566.php - The root cause was that getConditionalSpecifiedTypes set rootExpr to the call argument via inner specifyTypesInCondition, causing findSpecifiedType to short-circuit with a false "always evaluates to false" result
3123f73 to
59a1dfc
Compare
src/Analyser/TypeSpecifier.php
Outdated
| && ($ifType instanceof NeverType || $elseType instanceof NeverType) | ||
| ) |
There was a problem hiding this comment.
You didn't put my suggestion on the right line.
You wrote
$argumentExpr instanceof Node\Scalar
|| ($argumentExpr instanceof ConstFetch && in_array(strtolower($argumentExpr->name->toString()), ['true', 'false', 'null'], true))
&& ($ifType instanceof NeverType || $elseType instanceof NeverType)
instead of
(
$argumentExpr instanceof Node\Scalar
|| ($argumentExpr instanceof ConstFetch && in_array(strtolower($argumentExpr->name->toString()), ['true', 'false', 'null'], true))
)
&& ($ifType instanceof NeverType || $elseType instanceof NeverType)
There was a problem hiding this comment.
I just realized it a second ago :-/
92b8af8 to
d1f2dcb
Compare
|
This pull request has been marked as ready for review. |
|
@VincentLanglet thanks for your support. I think this is now good to go without the regressions my previous attempts had |
Fixes phpstan/phpstan#13566
Closes phpstan/phpstan#10337
Prevents that function/method calls with conditional-defined return types like
/** @return ($exit is true ? never : void) */- which compare against constant-values - do not lead to a "always false/true" error.