Skip to content
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

Improve sprintf return type inference #3168

Closed
wants to merge 8 commits into from
Closed

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jun 19, 2024

Comment on lines +64 to +71
// XXX should be string because of invalid arguments count
assertType('non-falsy-string&numeric-string', sprintf('%10$14F', $mixed, $s));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after #3126 is merged we have the necessary PrintfHelper to decide about the invalid number of arguments/placeholders

@staabm
Copy link
Contributor Author

staabm commented Jun 20, 2024

the composer error is valid, as we previously inferred a non-empty-string return type, even though the sprintf pattern is not known at static analysis time.

other errors are the same ones are unrelated

@staabm staabm marked this pull request as ready for review June 20, 2024 07:45
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@staabm staabm force-pushed the bug11201 branch 4 times, most recently from cfc5771 to fc9baf6 Compare June 22, 2024 06:48
@staabm
Copy link
Contributor Author

staabm commented Jun 22, 2024

the reported phpstan error is interesstig.. it seems - depending on some unknown factor - reports that we are catching a non-throwable but ignoring this very same error by identifer leads to a "No error with identifier catch.notThrowable is reported on line 200."

see the 2 variants at

(its unrelated to this PR though)

@staabm
Copy link
Contributor Author

staabm commented Jun 22, 2024

I think its related to this Consistency::flexEntity call in the exception classes.. some class-alias stuff is going on there.. this might lead to a race condition depending on the order which classes will be scanned when

@ondrejmirtes
Copy link
Member

There's an opportunity to grab the code from Hoa packages and make a small single modern library with no magic and simple PSR-4 autoloading and replace Hoa in phpstan-src. I might look into it this summer.

@staabm staabm force-pushed the bug11201 branch 2 times, most recently from 15bbfa6 to fc9baf6 Compare June 22, 2024 12:58
@staabm
Copy link
Contributor Author

staabm commented Jun 22, 2024

I might look into it this summer.

ok, what can we do to fix the build until then?

@ondrejmirtes
Copy link
Member

Try to rebase on top of: 3233155

@staabm
Copy link
Contributor Author

staabm commented Jun 24, 2024

Try to rebase on top of: 3233155

looks great, thanks

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry. I see the diff of src/Type/Php/SprintfFunctionDynamicReturnTypeExtension.php and my brain just freezes. I'm not able to review this. Can you do this in smaller steps, or maybe not move that many things around?

"Make the change easy, then make the easy change."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants