Skip to content

More precise constant variants of BooleanType #3781

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

Merged
merged 5 commits into from
Jan 11, 2025

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jan 11, 2025

instead of resolving bool into true/false in the extension, lets do it in the type-system itself

@@ -53,4 +53,4 @@ function returnsBool(): bool {
assertType("' 1'", $s);

$s = sprintf('%20s', returnsBool());
assertType("lowercase-string&non-falsy-string", $s);
assertType("' '|' 1'", $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.

looks great, see https://3v4l.org/ipPIP

@staabm
Copy link
Contributor Author

staabm commented Jan 11, 2025

@herndlm opinions?

@staabm staabm marked this pull request as ready for review January 11, 2025 10:35
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@herndlm
Copy link
Contributor

herndlm commented Jan 11, 2025

Interesting idea! Makes sense IMO for "finite" types like that

@staabm
Copy link
Contributor Author

staabm commented Jan 11, 2025

"finite" types like that

hmm interessting wording you use here. makes me wonder what the semantic difference of

getFiniteTypes and getConstantScalarTypes is .. maybe just "enum", integer-range?

@herndlm
Copy link
Contributor

herndlm commented Jan 11, 2025

I might be also just mixing up things. Don't even know all those related methods that currently exist on the interface. But good point 🤔

@herndlm
Copy link
Contributor

herndlm commented Jan 11, 2025

Quickly checked, looks like you could implement that finite method as well here

@staabm
Copy link
Contributor Author

staabm commented Jan 11, 2025

Quickly checked, looks like you could implement that finite method as well here

its already implemened

public function getConstantStrings(): array
{
return [];
return [new ConstantStringType('1'), new ConstantStringType('0')];
Copy link
Member

Choose a reason for hiding this comment

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

Nope. This function isn't used for loose type casts like that.

@ondrejmirtes ondrejmirtes merged commit 76740fd into phpstan:2.1.x Jan 11, 2025
426 of 427 checks passed
@ondrejmirtes
Copy link
Member

Thank yuo.

@staabm staabm deleted the const-bool branch January 11, 2025 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants