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

Implement Type->looseCompare(type) #2216

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

Draft
staabm wants to merge 37 commits into phpstan:1.10.x
base: 1.10.x
Choose a base branch
Loading
from staabm:loose-compare-new

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Feb 2, 2023

Copy link
Contributor Author

staabm commented Feb 2, 2023
edited
Loading

for now I have implemented the looseCompare methods for all types.
now I need to have a look at the failling tests and afterwards type narrowing

@staabm staabm force-pushed the loose-compare-new branch 9 times, most recently from 1337c88 to 8db02be Compare February 2, 2023 22:44
Copy link
Member

Type narrowing is a separate concern, I wouldn't do that here.

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

I don't see the table of == comparison described anywhere in this PR https://www.php.net/manual/en/types.comparisons.php.

All types need to take into account being compared to any other type. For example this implementation in NullType is too naive:

return $type->isNull()->toBooleanType();

Because all of the following examples are true:

null == []
null == false
null == 0
null == ""

Copy link
Member

Also an idea for a preliminary or a future PR - NanType. See the last comment here: https://www.php.net/manual/en/function.is-nan.php

Copy link
Contributor Author

staabm commented Feb 4, 2023
edited
Loading

I have implemented a few basic types and added tests for them in loose-compare.php. please have a look whether this is done how you imagined it.

btw: this PR will get really big if we implement all combinations for all types here.
do you think we could split this, e.g. doing basic and simple object type in one PR, and all more specialized types in separate PRs?

thank you

@staabm staabm force-pushed the loose-compare-new branch 2 times, most recently from 3fe288d to 9aed5d1 Compare February 4, 2023 14:41
Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

I like StringType::looseCompare but otherwise it's still gonna be a lot of work 😅 And we're not even diving into type narrowing now. I think it's obvious why I was avoiding this topic until now 😂

staabm and others added 27 commits February 12, 2023 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ondrejmirtes ondrejmirtes ondrejmirtes requested changes

+1 more reviewer

@herndlm herndlm herndlm left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

implement loose comparison semantics

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