-
Notifications
You must be signed in to change notification settings - Fork 66
Implement offset access type syntax #119
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
Conversation
ondrejmirtes
left a comment
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.
A test for the A [B] scenario wouldn't hurt :)
| ]), | ||
| ]; | ||
|
|
||
| yield [ |
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.
Tests for A [B] already exist - just a few lines above
|
@JanTvrdik what's the reason for the "confused" reaction? Do you disagree with the idea in general, with the implementation, or something else? |
|
The context: phpstan/phpstan#7094 |
| /** @var TypeNode */ | ||
| public $offset; | ||
|
|
||
| public function __construct(TypeNode $type, TypeNode $offset) |
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.
Does it make sense to allow any TypeNode here? Shouldn't it be narrowed down to just IdentifierTypeNode?
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.
While it might make no sense in practice, array{foo: string}['foo'] could resolve to string.
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, make sure to add a test case for this in phpstan-src when you work on it :) Thanks :)
This implements offset access types keeping as much BC as possible. Notably, whitespace between the type and
[is not allowed (soA[B]is valid butA [B]parses as justA, as before)