Implement offset access type syntax#119
Conversation
ondrejmirtes
left a comment
There was a problem hiding this comment.
A test for the A [B] scenario wouldn't hurt :)
| ]), | ||
| ]; | ||
|
|
||
| yield [ |
There was a problem hiding this comment.
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.
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.
While it might make no sense in practice, array{foo: string}['foo'] could resolve to string.
There was a problem hiding this comment.
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)