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

Better type inference and type checking for large union types used in array keys/values #9022

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ public static function analyze(
$item_key_type = TypeCombiner::combine(
$array_creation_info->item_key_atomic_types,
$codebase,
false,
true,
30,
);
} else {
$item_key_type = null;
Expand All @@ -109,9 +106,6 @@ public static function analyze(
$item_value_type = TypeCombiner::combine(
$array_creation_info->item_value_atomic_types,
$codebase,
false,
true,
30,
);
} else {
$item_value_type = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,21 +548,13 @@ private static function inferArrayType(
if ($array_creation_info->item_key_atomic_types) {
$item_key_type = TypeCombiner::combine(
$array_creation_info->item_key_atomic_types,
null,
false,
true,
30,
);
}

$item_value_type = null;
if ($array_creation_info->item_value_atomic_types) {
$item_value_type = TypeCombiner::combine(
$array_creation_info->item_value_atomic_types,
null,
false,
true,
30,
);
}

Expand Down
13 changes: 13 additions & 0 deletions tests/ArrayFunctionCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2523,6 +2523,19 @@ function findit(Closure $x): void
}
',
],
'functionRequiringArrayWithLargeUnionTypeKeyAllowsInputArrayUsingSameUnionForItsKeys' => [
'code' => '<?php
/** @psalm-type TLargeUnion = 1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31 */

/** @return TLargeUnion */
function makeKey(): int { throw new Exception("irrelevant"); }

/** @param array<TLargeUnion, mixed> $_input */
function consumeArray(array $_input): void {}

consumeArray([makeKey() => null]);
',
],
];
}

Expand Down