-
Notifications
You must be signed in to change notification settings - Fork 473
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
Improved sprintf() inference #3232
Conversation
$s = sprintf('%20s', 'abc'); | ||
assertType("' abc'", $s); | ||
|
||
$s = sprintf('%20s', true); | ||
assertType("' 1'", $s); | ||
|
||
$s = sprintf('%20s', returnsBool()); | ||
assertType("non-falsy-string", $s); |
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.
regressions from #3167 which made sprintf
1:1 return constant values from arguments (bypassing sprintf formatting rules)
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.
//cc @pilif
assertType('non-falsy-string&numeric-string', sprintf('%2$14s', $mixed, $posInt)); | ||
assertType('non-falsy-string&numeric-string', sprintf('%2$14s', $mixed, $negInt)); |
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.
improvements because of the added toString()
handling
This pull request has been marked as ready for review. |
@@ -115,19 +119,19 @@ public function getTypeFromFunctionCall( | |||
$returnType = new StringType(); | |||
} | |||
|
|||
return $this->getConstantType($args, $returnType, $functionReflection, $scope); |
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.
instead of building the general return type first and pass it as a default-return into getConstantType()
we now invoke getConstantType()
first and build the general return type only if we were not able to infer a constant type in the first place
This pull request has been marked as ready for review. |
Thank you! |
another small improvement while thinking thru more details of #3192
it fixes a bug regressed with #3167