-
Notifications
You must be signed in to change notification settings - Fork 112
More precise type inference with unary plus and minus #580
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1261,7 +1261,19 @@ public function walkArithmeticFactor($factor): string | |
| $primary = $factor->arithmeticPrimary; | ||
|
|
||
| $type = $this->unmarshalType($this->walkArithmeticPrimary($primary)); | ||
| $type = TypeUtils::generalizeType($type, GeneralizePrecision::lessSpecific()); | ||
|
|
||
| if ($type instanceof ConstantIntegerType && $factor->sign === false) { | ||
| $type = new ConstantIntegerType($type->getValue() * -1); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test I'm trying to write produces wrong results as those two are not merged yet:
DQL from the test: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test added, it will fail once rebased on those PRs. |
||
|
|
||
| } elseif ($type instanceof IntegerRangeType && $factor->sign === false) { | ||
| $type = IntegerRangeType::fromInterval( | ||
| $type->getMax() === null ? null : $type->getMax() * -1, | ||
| $type->getMin() === null ? null : $type->getMin() * -1 | ||
| ); | ||
|
|
||
| } elseif ($type instanceof ConstantFloatType && $factor->sign === false) { | ||
| $type = new ConstantFloatType($type->getValue() * -1); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same questions as above |
||
| } | ||
|
|
||
| return $this->marshalType($type); | ||
| } | ||
|
|
||