-
Notifications
You must be signed in to change notification settings - Fork 651
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
Splat in constant array expression produces wrong array shape #6263
Comments
I found these snippets: https://psalm.dev/r/fb451afec9<?php
final class Token
{
public const ONE = [
16 => 16,
21 => 21,
];
public const TWO = [
17 => 17,
22 => 22,
];
public const THREE = [
18 => 18,
23 => 23,
];
public const RESULT = [...self::ONE, ...self::TWO, ...self::THREE];
}
$_t = Token::RESULT;
/** @psalm-trace $_t */;
|
I took a quick glance at it. The issue is in here:
We loop over the class constants and we use SimpleTypeInferer::infer to calculate the type. Unfortunately, this method doesn't handle unpacking at all. We should probably take a look at how it's handled in ArrayAnalyzer::handleUnpackedArray and reuse code somehow |
@ondrejmirtes PHPStan also suffers from this bug: https://phpstan.org/r/9d00884a-5311-45c1-ad35-f2d7cdcbb852 |
@weirdan FYI you can dump types in PHPStan, similar to @psalm-trace: https://phpstan.org/r/4b4198b8-b52a-4c72-b185-42b3b5c8dc94 |
This fixes int offset inference and adds handling for array unpacks in constant arrays. Mostly it's copy/pasted from `ArrayAnalyzer` with further adjustments. Fixes vimeo#6263 Fixes vimeo#6289
Please open a bug report in PHPStan's repo, thanks :) |
This fixes int offset inference and adds handling for array unpacks in constant arrays. Mostly it's copy/pasted from `ArrayAnalyzer` with further adjustments. Fixes vimeo#6263 Fixes vimeo#6289
https://psalm.dev/r/fb451afec9
Expected: flat list (https://3v4l.org/0IdDo)
The text was updated successfully, but these errors were encountered: