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
AddVoidReturnTypeWhereNoReturnRector: fix never type handling #4918
Conversation
|
||
final class ThrowsMethod | ||
{ | ||
protected function getValues(): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the bug I am trying to solve. a method, which contains a non-top-level never type, should get the void
return type as it cannot not get a never type
I don't have an idea yet how to solve it |
|
||
final class ExitMethod | ||
{ | ||
protected function getValues() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when not yet supported, add void
is fine imo, than use ReturnNeverTypeRector
when feature available, the void
will be changed to never
, see
https://getrector.com/demo/b32ecefb-b0b4-40ff-be70-c8c2bd5eea5b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this test-case because my interpretation of
rector-src/rules/TypeDeclaration/TypeInferer/SilentVoidResolver.php
Lines 143 to 146 in c171814
private function hasNeverType(ClassMethod | Closure | Function_ $functionLike): bool | |
{ | |
return $this->betterNodeFinder->hasInstancesOf($functionLike, [Throw_::class]); | |
} |
was that we don't want to add void
when a never type is contained.
the idea was to prevent regressions of previous behaviour.
I don't know why the logic is there otherwise
|
||
final class NeverMethod | ||
{ | ||
protected function getValues() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same with here, the ReturnNeverTypeRector
will change void
to never
when feature available, see
https://getrector.com/demo/dde48f5c-7497-489c-9392-3043e45cead5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm ok, I moved the pre PR-existing test from a "skip" into a regular test which expects :void
beeing added.
...eclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector/Fixture/exception.php.inc
Outdated
Show resolved
Hide resolved
...eclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector/Fixture/exception.php.inc
Outdated
Show resolved
Hide resolved
…peWhereNoReturnRector/Fixture/exception.php.inc Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
…peWhereNoReturnRector/Fixture/exception.php.inc Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@staabm I am ok with this 👍
@TomasVotruba I am merging it ;), this will improve php 7.x return void, when user use php 8.1, user can run |
No description provided.