Skip to content

Conversation

mvorisek
Copy link

@mvorisek mvorisek commented Jun 1, 2022

@mvorisek mvorisek force-pushed the testcase_dynamic_model_method branch 6 times, most recently from c1621c7 to e2444d3 Compare June 1, 2022 09:28
@mvorisek mvorisek force-pushed the testcase_dynamic_model_method branch 2 times, most recently from e5cb2ef to bb4823d Compare June 1, 2022 13:00
@mvorisek mvorisek force-pushed the testcase_dynamic_model_method branch 2 times, most recently from ef5ebfd to 00ace67 Compare June 1, 2022 14:07
@mvorisek mvorisek changed the title DynamicMethodReturnTypeExtension test for bug 7344 Fix TypeUtils::getDirectClassNames for nested type Jun 1, 2022
@ondrejmirtes
Copy link
Member

Do you know you can run the code locally too, righr? ;)

@mvorisek mvorisek force-pushed the testcase_dynamic_model_method branch from b435d37 to 7549ae9 Compare June 1, 2022 14:27
@mvorisek mvorisek marked this pull request as ready for review June 1, 2022 14:32
@mvorisek mvorisek force-pushed the testcase_dynamic_model_method branch from 7549ae9 to 20596c6 Compare June 1, 2022 14:32
@mvorisek
Copy link
Author

mvorisek commented Jun 1, 2022

Do you know you can run the code locally too, righr? ;)

yes, I know, I located the issue on my project and then hoped I will need less pushes here for the repro :)

@mvorisek
Copy link
Author

mvorisek commented Jun 1, 2022

now the issue is fixed incl. full & simple functional test - can you please merge and tag a new release?

@@ -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) {
Copy link
Member

Choose a reason for hiding this comment

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

Please use self

Copy link
Author

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) {
Copy link
Member

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?

Copy link
Author

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

Copy link
Member

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.

Copy link
Author

@mvorisek mvorisek Jun 2, 2022

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.

Copy link
Member

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.

@ondrejmirtes ondrejmirtes force-pushed the testcase_dynamic_model_method branch from 81b7c93 to 26d8fde Compare June 2, 2022 15:53
@ondrejmirtes ondrejmirtes merged commit 0bc75d9 into phpstan:1.7.x Jun 2, 2022
@ondrejmirtes
Copy link
Member

Thanks.

@mvorisek mvorisek deleted the testcase_dynamic_model_method branch June 2, 2022 16:14
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.

DynamicMethodReturnTypeExtension::getTypeFromMethodCall is not executed for union type
2 participants