Skip to content

Treat array-shapes without keys as tuples#3872

Closed
zonuexe wants to merge 4 commits into
phpstan:2.1.xfrom
zonuexe:feature/keyless-constant-as-tuple
Closed

Treat array-shapes without keys as tuples#3872
zonuexe wants to merge 4 commits into
phpstan:2.1.xfrom
zonuexe:feature/keyless-constant-as-tuple

Conversation

@zonuexe

@zonuexe zonuexe commented Mar 11, 2025

Copy link
Copy Markdown
Contributor

@zonuexe zonuexe marked this pull request as draft March 11, 2025 11:52
@zonuexe zonuexe changed the title Impl keyless array-shapes as Tuple Treat array-shapes without keys as tuples Mar 11, 2025
@zonuexe

zonuexe commented Mar 11, 2025

Copy link
Copy Markdown
Contributor Author

I'm a bit surprised that this single change digs up list-shapes that were previously imported from Psalm.

2) PHPStan\Analyser\NodeScopeResolverTest::testFile with data set "tests/PHPStan/Analyser/nsrt/list-shapes.php" ('/home/runner/work/phpstan-src...es.php')
Failed assertions in /home/runner/work/phpstan-src/phpstan-src/tests/PHPStan/Analyser/nsrt/list-shapes.php:

Line 21:
Expected: array{'a'}
Actual:   list{'a'}

Line 22:
Expected: array{'a', 'b'}
Actual:   list{'a', 'b'}

Line 23:
Expected: array{0: 'a', 1?: 'b'}
Actual:   list{0: 'a', 1?: 'b'}

@zonuexe zonuexe force-pushed the feature/keyless-constant-as-tuple branch from dbc452f to c044612 Compare March 11, 2025 12:42
@ondrejmirtes

Copy link
Copy Markdown
Member

We tried something similar here but decided against it #3381

@ondrejmirtes

Copy link
Copy Markdown
Member

I don't think we should make any difference between array{int} and array{0: int}`. It should be the same thing...

@zonuexe

zonuexe commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favour of the plan in phpstan/phpstan#14939: the functionMap migration continues in #6024 (expanded with hrtime, preg_split, sys_getloadavg), and the semantic change will be re-derived on top of the current sealed-array implementation behind bleeding edge. The approach here — treating any explicit key as indeterminate — turned out to over-demote array{0: T} and array{}, which must stay lists (see the RFC for the denotational rule).

@zonuexe zonuexe closed this Jul 8, 2026
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.

2 participants