-
Notifications
You must be signed in to change notification settings - Fork 506
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
{"WIP"=>"Add to support List shapes"} #2202
Conversation
continue work in a few days |
This pull request has been marked as ready for review. |
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'd choose a different implementation path.
- Reset everything in src/, leave just the tests.
- In TypeNodeResolver, intersect
$builder->getArray()
withAccessoryArrayListType
if kind is list. - In
IntersectionType::describeItself
there's a section that makes sure thatarray<...>&list
is described aslist<...>
. Please write similar logic there so thatarray{...}&list
is described aslist{...}
.
Thank you.
src/PhpDoc/TypeNodeResolver.php
Outdated
$arrayType = $builder->getArray(); | ||
if ($typeNode->kind === ArrayShapeNode::KIND_LIST) { | ||
$arrayType = AccessoryArrayListType::intersectWith($arrayType); | ||
var_dump($arrayType); |
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.
array{0: 'a', 1: 'b'}&list
is normalized to array{0: 'a', 1: 'b'}
.
AccessoryArrayListType::intersectWith($arrayType)
always returns the operand $arrayType: ConstantArrayType
instead of IntersectionType
because the following equality always holds.
(new AccessoryArrayListType)->isSuperTypeOf($arrayType)->yes() === true
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.
@ondrejmirtes AccessoryArrayListType::intersectWith($arrayType)
never returns IntersectionType
so changing IntersectionType::describeItself()
doesn't seem to accomplish what you want, any ideas?
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.
array{0: 'a', 1: 'b'}
is always a list so that's why the &list
part is omitted and that's why it's not an intersection type. So we probably don't need to worry about this at all. The point of list{...}
should be to reject types like list{foo: 1}
.
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.
ok.
src/Type/IntersectionType.php
Outdated
} | ||
$describedTypes[$i] = 'list{' . substr($typeDescription, strlen('array{')); | ||
continue; | ||
} |
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.
- In
IntersectionType::describeItself
there's a section that makes sure thatarray<...>&list
is described aslist<...>
. Please write similar logic there so thatarray{...}&list
is described aslist{...}
.
array{0: 'a', 1: 'b'}
is always a list so that's why the&list
part is omitted and that's why it's not an intersection type. So we probably don't need to worry about this at all. The point oflist{...}
should be to reject types likelist{foo: 1}
.
As you say array{0: 'a', 1: 'b'}&list
is always ConstantArrayType
not IntersectionType
. Changing IntersectionType::describeItself()
for print list{}
seems to have no effect.
Reset everything in src/, leave just the tests.
Maybe I need to reapply the reverted fa7bcee09da8565bfe9f5a557c2894922f74faf1 and change ConstantArrayType
.
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.
Do not overthink this :) It's fine to describe list{1}
in PHPDoc as array{1}
with dumpType.
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 think you can delete this change without anything failing.
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 add a test so that we can see that list{foo: 1}
reports:
PHPDoc tag @param for parameter $a contains unresolvable type.
in IncompatiblePhpDocTypeRuleTest
src/Type/IntersectionType.php
Outdated
} | ||
$describedTypes[$i] = 'list{' . substr($typeDescription, strlen('array{')); | ||
continue; | ||
} |
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 think you can delete this change without anything failing.
Rebasing to see if the Rector failures are fixed. |
Thank you. |
refs phpstan/phpstan#8789, phpstan/phpdoc-parser#175
no tests yet