Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Dec 19, 2022
1 parent ab2692f commit 4fb5a61
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Psalm/Internal/Type/TypeCombiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,11 @@ private static function scrapeTypeProperties(

if (!$candidate_property_type->possibly_undefined) {
$has_defined_keys = true;
} elseif ($combination->fallbackKeyContains($candidate_property_name)) {
}

if (($candidate_property_type->possibly_undefined || ($value_type->possibly_undefined ?? true))
&& $combination->fallbackKeyContains($candidate_property_name)
) {
$combination->objectlike_entries[$candidate_property_name] = Type::combineUnionTypes(
$combination->objectlike_entries[$candidate_property_name],
$combination->objectlike_value_type,
Expand Down
21 changes: 21 additions & 0 deletions tests/TypeCombinationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Psalm\Type;
use Psalm\Type\Atomic;

use function array_reverse;

class TypeCombinationTest extends TestCase
{
use ValidCodeAnalysisTestTrait;
Expand All @@ -30,6 +32,11 @@ public function testValidTypeCombination(string $expected, array $types): void
$expected,
TypeCombiner::combine($converted_types)->getId(),
);

$this->assertSame(
$expected,
TypeCombiner::combine(array_reverse($converted_types))->getId(),
);
}

public function providerValidCodeParse(): iterable
Expand Down Expand Up @@ -90,6 +97,20 @@ function expectsTraversableOrArray($_a): void
public function providerTestValidTypeCombination(): array
{
return [
'complexArrayFallback1' => [
'array{other_references: list<Psalm\Internal\Analyzer\DataFlowNodeData>|null, taint_trace: list<array<array-key, mixed>>|null, ...<string, mixed>}',
[
'array{other_references: list<Psalm\Internal\Analyzer\DataFlowNodeData>|null, taint_trace: null}&array<string, mixed>',
'array{other_references: list<Psalm\Internal\Analyzer\DataFlowNodeData>|null, taint_trace: list<array<array-key, mixed>>}&array<string, mixed>',
],
],
'complexArrayFallback2' => [
'list{0?: 0|a, 1?: 0|a, ...<int<0, max>, a>}',
[
'list<a>',
'list{0, 0}',
],
],
'intOrString' => [
'int|string',
[
Expand Down

0 comments on commit 4fb5a61

Please sign in to comment.