Fix phpstan-src build errors#375
Conversation
|
This is not the right fix. The failing test actually shows a real issue. PHPStan dynamic return type extension needs to be written instead. |
ondrejmirtes
left a comment
There was a problem hiding this comment.
And please rebase this on top of 1.3.x.
| } | ||
|
|
||
| $callbackReturnType = $scope->getType($methodCall->getArgs()[1]->value); | ||
| if ($callbackReturnType instanceof ClosureType) { |
There was a problem hiding this comment.
CacheInterface accepts any callable, instanceof *Type is always wrong.
Type has getCallableParametersAcceptors, check isCallable()->yes() and then call this method.
composer.json
Outdated
| "php": "^7.2 || ^8.0", | ||
| "ext-simplexml": "*", | ||
| "phpstan/phpstan": "^1.10.36" | ||
| "phpstan/phpstan": "^1.10.49" |
There was a problem hiding this comment.
since the behaviour we fix with this PR only affects 1.10.49+
refs phpstan/phpstan-src#2818
There was a problem hiding this comment.
I disagree with this change. The dynamic return type extension is valid and works for older PHPStan versions too.
composer.json
Outdated
| "php": "^7.2 || ^8.0", | ||
| "ext-simplexml": "*", | ||
| "phpstan/phpstan": "^1.10.36" | ||
| "phpstan/phpstan": "^1.10.49" |
There was a problem hiding this comment.
I disagree with this change. The dynamic return type extension is valid and works for older PHPStan versions too.
| // generalize template parameters | ||
| if ($returnType->isConstantScalarValue()->yes()) { | ||
| return $returnType->generalize(GeneralizePrecision::lessSpecific()); | ||
| } |
There was a problem hiding this comment.
Please test a scenario where this is not a scalar. The $returnType should still be used.
There was a problem hiding this comment.
I'd rather return $returnType here too.
| function testNonScalarCacheCallable(\Symfony\Contracts\Cache\CacheInterface $cache, callable $fn): void { | ||
| $result = $cache->get('foo', $fn); | ||
|
|
||
| assertType('string', $result); |
There was a problem hiding this comment.
I feel like non-empty-string should be generalized to string. Which means we'll likely have to always generalize by GeneralizePrecision::templateArgument().
There was a problem hiding this comment.
wasn't aware GeneralizePrecision::templateArgument() is a thing 😅
|
Thank you. |
before this PR