Skip to content
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

Fix various array spread issues. #8044

Merged
merged 4 commits into from Jul 26, 2022

Conversation

AndrolGenhald
Copy link
Collaborator

@AndrolGenhald AndrolGenhald commented Jun 2, 2022

@AndrolGenhald
Copy link
Collaborator Author

Also unblocks #7319.

@AndrolGenhald AndrolGenhald added the release:fix The PR will be included in 'Fixes' section of the release notes label Jun 2, 2022
@@ -55,4 +55,6 @@ class ArrayCreationInfo
* @var array<string, DataFlowNode>
*/
public $parent_taint_nodes = [];

public bool $can_be_empty = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weirdan I probably let some slip before, but what do we want to do with typed properties? I'd be all for it, but I remember Matt saying there's a performance issues on hot paths. Should we enforce that one way or another?

@orklah
Copy link
Collaborator

orklah commented Jun 2, 2022

Looks great!

Comment on lines -503 to 515
$array_creation_info->item_value_atomic_types[] = new TMixed();

if ($item_key_value !== null
&& count($array_creation_info->property_types) <= $config->max_shaped_array_size
) {
$array_creation_info->property_types[$item_key_value] = Type::getMixed();
} else {
$array_creation_info->can_create_objectlike = false;
$array_creation_info->item_key_atomic_types = array_merge(
$array_creation_info->item_key_atomic_types,
array_values($key_type->getAtomicTypes())
);
$array_creation_info->item_value_atomic_types[] = new TMixed();
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually untested and I couldn't find a way to test it.

@orklah
Copy link
Collaborator

orklah commented Jun 8, 2022

I'll wait after merging 4.x on master to merge this, it'll probably be easier for you to resolve the conflict

 - Correctly infer `array` and `list` instead of `non-empty-array` and `non-empty-list` (fixes vimeo#7296)
 - Add support for spreading string keys (fixes vimeo#7297).
 - Show issue when trying to unpack non-iterable
 - Show issue when trying to unpack iterable with non-array-key key
 - Re-added invalid PHP 8.0 tests removed in vimeo#6613
 - Unpacked lists with known keys will be inferred as eg `array{0: int, 1: int}<int<0, max>, int>` now but will still be treated as lists
 - Unpacked arrays with known keys will now be inferred as eg `array{a: string, b: string}<int, int>` instead of `array<int|string, int|string>`
@AndrolGenhald AndrolGenhald force-pushed the feature/improve-array-spreading branch from 56c88d9 to 094621d Compare July 26, 2022 17:00
@AndrolGenhald
Copy link
Collaborator Author

Rebased, should be gtg now, @orklah not sure if you're done reviewing.

@orklah
Copy link
Collaborator

orklah commented Jul 26, 2022

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:fix The PR will be included in 'Fixes' section of the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants