-
Notifications
You must be signed in to change notification settings - Fork 529
Fix TypeUtils::getDirectClassNames for nested type #1380
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
Fix TypeUtils::getDirectClassNames for nested type #1380
Conversation
c1621c7
to
e2444d3
Compare
e5cb2ef
to
bb4823d
Compare
ef5ebfd
to
00ace67
Compare
Do you know you can run the code locally too, righr? ;) |
b435d37
to
7549ae9
Compare
7549ae9
to
20596c6
Compare
yes, I know, I located the issue on my project and then hoped I will need less pushes here for the repro :) |
now the issue is fixed incl. full & simple functional test - can you please merge and tag a new release? |
src/Type/TypeUtils.php
Outdated
@@ -145,14 +146,12 @@ public static function getDirectClassNames(Type $type): array | |||
if ($type instanceof UnionType || $type instanceof IntersectionType) { | |||
$classNames = []; | |||
foreach ($type->getTypes() as $innerType) { | |||
if (!$innerType instanceof TypeWithClassName) { | |||
continue; | |||
foreach (static::getDirectClassNames($innerType) as $n) { |
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.
Please use self
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.
done
Scope $scope | ||
): Type { | ||
// resolve static type and remove all virtual interfaces from it | ||
if ($methodCall instanceof StaticCall) { |
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 extension is too complicated. Can you just write a simple one just so we can verify it's actually executed? So we can see the method's return type isn't used but the one returned from an extension?
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 simplest impl. supporting unlimited nesting, please merge this test case as is
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.
The fixed issue can be demonstrated with a much simpler extension. Let's say you're writing an extension for a method that has string
return type, the extension can just return new IntegerType()
and we can assert that int
has been used.
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.
the issue was limited nesting support of union/intersect
This test does support unlimited nesting - it removes virtual interface and reresolves $this
/static
. I do not think this two needed operations can be further simplified.
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.
Alright, had to do it myself :P 26d8fde
I verified the test fails without the change in TypeUtils.
81b7c93
to
26d8fde
Compare
Thanks. |
fixes phpstan/phpstan#7344
needed for atk4/data#932