-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CacheInterface accepts any callable, instanceof *Type
is always wrong.
Type
has getCallableParametersAcceptors
, check isCallable()->yes()
and then call this method.
composer.json
Outdated
@@ -15,7 +15,7 @@ | |||
"require": { | |||
"php": "^7.2 || ^8.0", | |||
"ext-simplexml": "*", | |||
"phpstan/phpstan": "^1.10.36" | |||
"phpstan/phpstan": "^1.10.49" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree with this change. The dynamic return type extension is valid and works for older PHPStan versions too.
composer.json
Outdated
@@ -15,7 +15,7 @@ | |||
"require": { | |||
"php": "^7.2 || ^8.0", | |||
"ext-simplexml": "*", | |||
"phpstan/phpstan": "^1.10.36" | |||
"phpstan/phpstan": "^1.10.49" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please test a scenario where this is not a scalar. The $returnType
should still be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wasn't aware GeneralizePrecision::templateArgument()
is a thing 😅
Thank you. |
before this PR