mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Allow combined keys to be possibly undefined
This commit is contained in:
parent
a4a618c9e5
commit
06e850867d
@ -580,46 +580,46 @@ abstract class Type
|
||||
public static function combineUnionTypes(Union $type_1, Union $type_2)
|
||||
{
|
||||
if ($type_1->isMixed() || $type_2->isMixed()) {
|
||||
return Type::getMixed();
|
||||
}
|
||||
$combined_type = Type::getMixed();
|
||||
} else {
|
||||
$both_failed_reconciliation = false;
|
||||
|
||||
$both_failed_reconciliation = false;
|
||||
|
||||
if ($type_1->failed_reconciliation) {
|
||||
if ($type_2->failed_reconciliation) {
|
||||
$both_failed_reconciliation = true;
|
||||
} else {
|
||||
return $type_2;
|
||||
if ($type_1->failed_reconciliation) {
|
||||
if ($type_2->failed_reconciliation) {
|
||||
$both_failed_reconciliation = true;
|
||||
} else {
|
||||
return $type_2;
|
||||
}
|
||||
} elseif ($type_2->failed_reconciliation) {
|
||||
return $type_1;
|
||||
}
|
||||
} elseif ($type_2->failed_reconciliation) {
|
||||
return $type_1;
|
||||
}
|
||||
|
||||
$combined_type = self::combineTypes(
|
||||
array_merge(
|
||||
array_values($type_1->getTypes()),
|
||||
array_values($type_2->getTypes())
|
||||
)
|
||||
);
|
||||
$combined_type = self::combineTypes(
|
||||
array_merge(
|
||||
array_values($type_1->getTypes()),
|
||||
array_values($type_2->getTypes())
|
||||
)
|
||||
);
|
||||
|
||||
if (!$type_1->initialized || !$type_2->initialized) {
|
||||
$combined_type->initialized = false;
|
||||
}
|
||||
if (!$type_1->initialized || !$type_2->initialized) {
|
||||
$combined_type->initialized = false;
|
||||
}
|
||||
|
||||
if ($type_1->from_docblock || $type_2->from_docblock) {
|
||||
$combined_type->from_docblock = true;
|
||||
}
|
||||
if ($type_1->from_docblock || $type_2->from_docblock) {
|
||||
$combined_type->from_docblock = true;
|
||||
}
|
||||
|
||||
if ($type_1->ignore_nullable_issues || $type_2->ignore_nullable_issues) {
|
||||
$combined_type->ignore_nullable_issues = true;
|
||||
}
|
||||
if ($type_1->ignore_nullable_issues || $type_2->ignore_nullable_issues) {
|
||||
$combined_type->ignore_nullable_issues = true;
|
||||
}
|
||||
|
||||
if ($type_1->ignore_falsable_issues || $type_2->ignore_falsable_issues) {
|
||||
$combined_type->ignore_falsable_issues = true;
|
||||
}
|
||||
if ($type_1->ignore_falsable_issues || $type_2->ignore_falsable_issues) {
|
||||
$combined_type->ignore_falsable_issues = true;
|
||||
}
|
||||
|
||||
if ($both_failed_reconciliation) {
|
||||
$combined_type->failed_reconciliation = true;
|
||||
if ($both_failed_reconciliation) {
|
||||
$combined_type->failed_reconciliation = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($type_1->possibly_undefined || $type_2->possibly_undefined) {
|
||||
|
@ -241,6 +241,15 @@ class TypeCombinationTest extends TestCase
|
||||
'array<int, array<int, string>>',
|
||||
],
|
||||
],
|
||||
'combinePossiblyUndefinedKeys' => [
|
||||
'array{a:bool, b?:mixed, d?:mixed}',
|
||||
[
|
||||
'array{a:false, b:mixed}',
|
||||
'array{a:false, b:mixed}',
|
||||
'array{a:true, d:mixed}',
|
||||
'array{a:true, d:mixed}',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user