Skip to content

Conversation

rvanvelzen
Copy link
Contributor

This implements offset access types keeping as much BC as possible. Notably, whitespace between the type and [ is not allowed (so A[B] is valid but A [B] parses as just A, as before)

Copy link
Member

@ondrejmirtes ondrejmirtes left a 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 [
Copy link
Contributor Author

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

@rvanvelzen
Copy link
Contributor Author

@JanTvrdik what's the reason for the "confused" reaction? Do you disagree with the idea in general, with the implementation, or something else?

@ondrejmirtes
Copy link
Member

The context: phpstan/phpstan#7094

/** @var TypeNode */
public $offset;

public function __construct(TypeNode $type, TypeNode $offset)
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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 :)

@ondrejmirtes ondrejmirtes merged commit 28cb38b into phpstan:1.4.x May 5, 2022
@rvanvelzen rvanvelzen deleted the offset-access-type branch May 17, 2022 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants