Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
ondrejmirtes merged 2 commits into phpstan:1.4.x from janedbal:arithmetic-factor
Jun 25, 2024

Conversation

@janedbal
Copy link
Contributor

@janedbal janedbal commented Jun 25, 2024

Separated from #506

$type = TypeUtils::generalizeType($type, GeneralizePrecision::lessSpecific());

if ($type instanceof ConstantIntegerType && $factor->sign === false) {
$type = new ConstantIntegerType($type->getValue() * -1);
Copy link
Member

@ondrejmirtes ondrejmirtes Jun 25, 2024

Choose a reason for hiding this comment

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

  1. What about sign=true?
  2. Looks like this doesn't have tests, at least from the diff

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Sign true is +1, sign null is 1, those dont change value of constant type
  2. 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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:

SELECT		-o.intColumn as minusInt,
		-o.floatColumn as minusFloat,
		-COUNT(o.intColumn) as minusIntRange
FROM		QueryResult\Entities\One o

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 ConstantFloatType && $factor->sign === false) {
$type = new ConstantFloatType($type->getValue() * -1);
Copy link
Member

@ondrejmirtes ondrejmirtes Jun 25, 2024

Choose a reason for hiding this comment

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

Same questions as above

@ondrejmirtes ondrejmirtes merged commit 25e200b into phpstan:1.4.x Jun 25, 2024
Copy link
Member

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ondrejmirtes ondrejmirtes ondrejmirtes requested changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /