Skip to content
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

Update test fixture: Do not remove true|T from phpdoc as it cannot be narrowed to native bool|T type hint #1662

Closed
wants to merge 1 commit into from

Conversation

simPod
Copy link
Contributor

@simPod simPod commented Jan 12, 2022

Original code does not compile

https://3v4l.org/klALN

@TomasVotruba
Copy link
Member

Hi, I'm not sure what is the issue here. Could you elaborate more?

@simPod
Copy link
Contributor Author

simPod commented Jan 12, 2022

Oh wait, native return typehint :false is valid? 😮

@simPod
Copy link
Contributor Author

simPod commented Jan 12, 2022

In that case, I have to rephrase it into true type hint https://3v4l.org/7PYjDY

@simPod simPod changed the title Update test fixture: Do not add false to native return type hint Update test fixture: Do not add true to native return type hint Jan 12, 2022
@simPod simPod force-pushed the false-return branch 2 times, most recently from 0a25ad5 to f6a9c05 Compare January 12, 2022 10:11
@TomasVotruba
Copy link
Member

Yes, since union types you can use false as part of union. Not standalone.

The true is never part of PHP native type in the snippet you provided. That behavior is correct.

@simPod
Copy link
Contributor Author

simPod commented Jan 12, 2022

That behavior is correct.

https://github.com/rectorphp/rector-src/pull/1662/files#diff-f3d0ea097fa32b9c2f428814dd887106a6ee7f837615e008bcb7ee219c01e301R27

the type should be converted into :bool|int but is wrongly converted to :true|int. Thus the test is failing.

@TomasVotruba
Copy link
Member

TomasVotruba commented Jan 12, 2022

Where do you see true|int? In CI here is int|bool

image

https://github.com/rectorphp/rector-src/runs/4787682009?check_suite_focus=true#step:5:85

@simPod
Copy link
Contributor Author

simPod commented Jan 12, 2022

The true|int should be kept but rector tries to remove it.

@simPod
Copy link
Contributor Author

simPod commented Jan 12, 2022

I confused myself here a bit. Will rephrase. 🤯

@simPod simPod changed the title Update test fixture: Do not add true to native return type hint Update test fixture: Do not remove true|T from phpdoc as it cannot be narrowed to native bool|T type hint Jan 12, 2022
@simPod
Copy link
Contributor Author

simPod commented Jan 12, 2022

So this removal is the issue

image

I know the method does not return false so I use true instead of bool.

@TomasVotruba
Copy link
Member

Yeah, union types can get little crazy in nestings. Been there.

Good, the last error makes sense. The comment should remain 👍

@samsonasik
Copy link
Member

@simPod I cherry-picked your commit at PR #1715

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants