mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Merge pull request #9562 from orklah/dez
always combine the result of expansions
This commit is contained in:
commit
7bdb2d6902
@ -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;
|
||||
|
@ -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}> */;
|
||||
}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user