More precise type inference with unary plus and minus#580
Merged
ondrejmirtes merged 2 commits intophpstan:1.4.xfrom Jun 25, 2024
Merged
More precise type inference with unary plus and minus#580ondrejmirtes merged 2 commits intophpstan:1.4.xfrom
ondrejmirtes merged 2 commits intophpstan:1.4.xfrom
Conversation
ondrejmirtes
requested changes
Jun 25, 2024
| $type = TypeUtils::generalizeType($type, GeneralizePrecision::lessSpecific()); | ||
|
|
||
| if ($type instanceof ConstantIntegerType && $factor->sign === false) { | ||
| $type = new ConstantIntegerType($type->getValue() * -1); |
Member
There was a problem hiding this comment.
- What about sign=true?
- Looks like this doesn't have tests, at least from the diff
Contributor
Author
There was a problem hiding this comment.
- Sign
trueis+1, signnullis1, those dont change value of constant type - Tests are present in origin: #506 commit. Mostly I didnt add testcases to the old test as that one is MUCH worse. But I can add simple one to this separated PR.
Contributor
Author
There was a problem hiding this comment.
The test I'm trying to write produces wrong results as those two are not merged yet:
- Proper aggregate function detection (even deeper in AST) #581
- Introduce DoctrineTypeDriverAwareDescriptor & DriverDetector #578
DQL from the test:
SELECT -o.intColumn as minusInt,
-o.floatColumn as minusFloat,
-COUNT(o.intColumn) as minusIntRange
FROM QueryResult\Entities\One o
Contributor
Author
There was a problem hiding this comment.
Test added, it will fail once rebased on those PRs.
| ); | ||
|
|
||
| } elseif ($type instanceof ConstantFloatType && $factor->sign === false) { | ||
| $type = new ConstantFloatType($type->getValue() * -1); |
Member
|
Thank you. |
This was referenced Jun 25, 2024
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Separated from #506