Skip to content

Commit 4fb5a61

Browse files
committed
Fix tests
1 parent ab2692f commit 4fb5a61

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Psalm/Internal/Type/TypeCombiner.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,11 @@ private static function scrapeTypeProperties(
676676

677677
if (!$candidate_property_type->possibly_undefined) {
678678
$has_defined_keys = true;
679-
} elseif ($combination->fallbackKeyContains($candidate_property_name)) {
679+
}
680+
681+
if (($candidate_property_type->possibly_undefined || ($value_type->possibly_undefined ?? true))
682+
&& $combination->fallbackKeyContains($candidate_property_name)
683+
) {
680684
$combination->objectlike_entries[$candidate_property_name] = Type::combineUnionTypes(
681685
$combination->objectlike_entries[$candidate_property_name],
682686
$combination->objectlike_value_type,

tests/TypeCombinationTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Psalm\Type;
88
use Psalm\Type\Atomic;
99

10+
use function array_reverse;
11+
1012
class TypeCombinationTest extends TestCase
1113
{
1214
use ValidCodeAnalysisTestTrait;
@@ -30,6 +32,11 @@ public function testValidTypeCombination(string $expected, array $types): void
3032
$expected,
3133
TypeCombiner::combine($converted_types)->getId(),
3234
);
35+
36+
$this->assertSame(
37+
$expected,
38+
TypeCombiner::combine(array_reverse($converted_types))->getId(),
39+
);
3340
}
3441

3542
public function providerValidCodeParse(): iterable
@@ -90,6 +97,20 @@ function expectsTraversableOrArray($_a): void
9097
public function providerTestValidTypeCombination(): array
9198
{
9299
return [
100+
'complexArrayFallback1' => [
101+
'array{other_references: list<Psalm\Internal\Analyzer\DataFlowNodeData>|null, taint_trace: list<array<array-key, mixed>>|null, ...<string, mixed>}',
102+
[
103+
'array{other_references: list<Psalm\Internal\Analyzer\DataFlowNodeData>|null, taint_trace: null}&array<string, mixed>',
104+
'array{other_references: list<Psalm\Internal\Analyzer\DataFlowNodeData>|null, taint_trace: list<array<array-key, mixed>>}&array<string, mixed>',
105+
],
106+
],
107+
'complexArrayFallback2' => [
108+
'list{0?: 0|a, 1?: 0|a, ...<int<0, max>, a>}',
109+
[
110+
'list<a>',
111+
'list{0, 0}',
112+
],
113+
],
93114
'intOrString' => [
94115
'int|string',
95116
[

0 commit comments

Comments
 (0)