Feature check mixed in binary operator#3231
Conversation
| return $this->getNeverType($leftType, $rightType); | ||
| } | ||
|
|
||
| if ($leftType->toNumber() instanceof ErrorType || $rightType->toNumber() instanceof ErrorType) { |
There was a problem hiding this comment.
I'm not sure whether this should only be enabled in bleeding edge. On the one hand, I don't see any other case in this class where return new ErrorType would be conditioned by bleeding edge. On the other hand, this can definitely result in new errors being reported without bleeding edge. E.g. 5 % [] now reports Binary operation "%" between 5 and array{} results in an error.
There was a problem hiding this comment.
The $int % $string use-case is even more compelling example of why it should apply only to bleeding edge.
| * @template T | ||
| * @param T $a | ||
| */ | ||
| function genericMixed(mixed $a): void |
There was a problem hiding this comment.
Some operators are missing from this test:
instanceofis not a binary operator in php-parser.&&,||,and,orandxor- everything can be converted to boolean. And they're already covered by strict-rules.??is OK to use with mixed.- Comparison operators are handled by
InvalidComparisonOperationRule.
| } elseif ($node instanceof Node\Expr\AssignOp\Plus || $node instanceof Node\Expr\BinaryOp\Plus) { | ||
| $callback = static fn (Type $type): bool => !$type->toNumber() instanceof ErrorType || $type->isArray()->yes(); |
There was a problem hiding this comment.
This is new, otherwise the code in this file should be the same with the exception of the early exit and not requiring $scope->getType($node) instanceof ErrorType anymore in bleeding edge.
|
This pull request has been marked as ready for review. |
|
the error in shopsys/shopsys on line looks like it could be fixed with a improved |
|
Thank you! |
The goal of this PR is to report mixed in binary operators. There's still a few other places where mixed is not properly reported (https://phpstan.org/r/c46a6ace-0135-46c0-a860-dd9d9b77b4ff), but those can be dealt with later.
Fixes: phpstan/phpstan#7538
Fixes: phpstan/phpstan#10440