1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 05:17:47 +01:00

always combine the result of expansions

This commit is contained in:
orklah 2023-03-23 20:43:48 +01:00
parent 0af503a9fb
commit dfd7ffc459
2 changed files with 36 additions and 14 deletions

View File

@ -77,8 +77,6 @@ class TypeExpander
): Union {
$new_return_type_parts = [];
$had_split_values = false;
foreach ($return_type->getAtomicTypes() as $return_type_part) {
$parts = self::expandAtomic(
$codebase,
@ -94,21 +92,13 @@ class TypeExpander
$throw_on_unresolvable_constant,
);
if ($return_type_part instanceof TTypeAlias || count($parts) > 1) {
$had_split_values = true;
}
$new_return_type_parts = [...$new_return_type_parts, ...$parts];
}
if ($had_split_values) {
$fleshed_out_type = TypeCombiner::combine(
$new_return_type_parts,
$codebase,
);
} else {
$fleshed_out_type = new Union($new_return_type_parts);
}
$fleshed_out_type = TypeCombiner::combine(
$new_return_type_parts,
$codebase,
);
$fleshed_out_type->from_docblock = $return_type->from_docblock;
$fleshed_out_type->ignore_nullable_issues = $return_type->ignore_nullable_issues;

View File

@ -771,6 +771,38 @@ class TypeAnnotationTest extends TestCase
'$output===' => 'array{phone: string}',
],
],
'combineAliasOfArrayAndArrayCorrectly' => [
'code' => '<?php
/**
* @psalm-type C = array{c: string}
*/
class A {}
/**
* @template F
*/
class D {
/**
* @param F $data
*/
public function __construct(public $data) {}
}
/**
* @psalm-import-type C from A
*/
class G {
/**
* @param D<array{b: bool}>|D<C> $_doesNotWork
*/
public function doesNotWork($_doesNotWork): void {
/** @psalm-check-type-exact $_doesNotWork = D<array{b?: bool, c?: string}> */;
}
}',
],
];
}