- Notifications
You must be signed in to change notification settings - Fork 538
Fix bitwise on mixed #4423
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
base: 2.1.x
Are you sure you want to change the base?
Fix bitwise on mixed #4423
Conversation
assertType('*ERROR*', $string & $mixed); | ||
assertType('*ERROR*', $stringOrInt & $stringOrInt); | ||
assertType('*ERROR*', $stringOrInt & $mixed); | ||
assertType('*ERROR*', $mixed & $mixed); |
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.
Current behavior https://phpstan.org/r/4e542067-2b33-4f87-8230-ca7b49937b10
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.
Mixed & mixed - should not be a error, right?
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 proposed a solution to get some feedback.
Things like
String ^ int|string
Int ^ int|string
Are already considered as an error because int ^ string is an error.
We have
Int ^ mixed considered to be int (even if it could ends up with int ^ string ?)
String ^ mixed considered to be an error (because it could ends up with string ^ int ?)
So I dunno what we want for mixed ^ mixed but it should not be considered as int. I see three solution:
- error
- int|string
- benevolentUnion int|string
I also dunno if we should change string ^ mixed.
I think we will need a decision from @ondrejmirtes unless you have a good suggestion @staabm ? ^^'
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.
IMO we should not treat something as an error, if it might be valid. mixed
could be a int
but just not typed.
therefore I think mixed ^ mixed should be a union of all possible results ^
can have.
but lets wait for ondrej
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.
IMO we should not treat something as an error, if it might be valid.
mixed
could be aint
but just not typed.therefore I think mixed ^ mixed should be a union of all possible results
^
can have.
Currently the InvalidBinaryOperationRule is using the strategy of checking if the result is an error in order to report it. So if you change int ^ int|string
from Error to int
this won't be reported anymore by the rule.
As an example, this is the current behavior with int + int|array
(an error and not an int)
https://phpstan.org/r/7f8dda05-7a6e-49d0-959e-e4bf4f038586
Following the existing strategy, it make sens to have int ^ int|string
and string ^ int|string
an error.
I just dunno what is expected for mixed...
Currently the fact mixed ^ mixed
still allow it to be reported by the rule because on higher level, mixed is transform into strictMixed and strictMixed ^ strictMixed
is an Error.
So the question might be
int ^ mixed = ? // currently int ; should be Error or string string ^ mixed = ? // currently Error ; should be Error or string mixed ^ mixed = ? // currently int ; should be Error or int|string
{ | ||
$mask = substr($mask, 0, strlen($data)); | ||
$data ^= $mask; | ||
return(base64_encode($data)); |
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.
Was reporting an error on level 5 on php 7.4 https://phpstan.org/r/12e63cdd-d516-4db2-a314-51da4f5c3101
bca011a
to d80297a
Compare
Closes phpstan/phpstan#8094