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

Add support for int-mask and int-mask-of types #1166

Merged
merged 5 commits into from Apr 4, 2022

Conversation

rvanvelzen
Copy link
Contributor

@rvanvelzen rvanvelzen commented Apr 2, 2022

@rvanvelzen rvanvelzen changed the title Int mask Add support for int-mask and int-mask-of types Apr 2, 2022
@rvanvelzen
Copy link
Contributor Author

I'm not convinced 0 should be part of the union by default, but it's easy enough to add. Psalm does include it, so for parity it might be best to include it.

@ondrejmirtes
Copy link
Member

Yeah, let's include 0. It's questionable, in some cases people want 0 and in some cases they don't, but we don't know which is which so let's do the wider and less annoying thing here.


if ($int !== 0) {
foreach ($values as $value) {
$values[] = $value | $int;
Copy link
Member

Choose a reason for hiding this comment

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

One idea for improvement. If the generated integer list is continuous, we could return IntegerRangeType instead.

@ondrejmirtes
Copy link
Member

Also please submit documentation for these types to https://phpstan.org/writing-php-code/phpdoc-types - there's a link to edit the page at the bottom.

@rvanvelzen rvanvelzen marked this pull request as ready for review April 4, 2022 11:29
@ondrejmirtes ondrejmirtes merged commit 7f5f55b into phpstan:1.6.x Apr 4, 2022
@ondrejmirtes
Copy link
Member

Perfect, thank you!

Two ideas:

  1. Test for a scenario when a value that's not power-of-2 (like 3) is part of the values.
  2. when a non-integer is mentioned in the PHPDoc, the resulting type should be ErrorType. That will get picked up as unresolvable type by a rule.

@Seldaek
Copy link
Contributor

Seldaek commented Apr 4, 2022

Great, thanks!

@rvanvelzen rvanvelzen deleted the int-mask branch April 25, 2022 11:49
ondrejmirtes pushed a commit to phpstan/phpstan that referenced this pull request Apr 26, 2022
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