mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 13:21:22 +01:00
always combine the result of expansions
This commit is contained in:
parent
0af503a9fb
commit
dfd7ffc459
@ -77,8 +77,6 @@ class TypeExpander
|
|||||||
): Union {
|
): Union {
|
||||||
$new_return_type_parts = [];
|
$new_return_type_parts = [];
|
||||||
|
|
||||||
$had_split_values = false;
|
|
||||||
|
|
||||||
foreach ($return_type->getAtomicTypes() as $return_type_part) {
|
foreach ($return_type->getAtomicTypes() as $return_type_part) {
|
||||||
$parts = self::expandAtomic(
|
$parts = self::expandAtomic(
|
||||||
$codebase,
|
$codebase,
|
||||||
@ -94,21 +92,13 @@ class TypeExpander
|
|||||||
$throw_on_unresolvable_constant,
|
$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];
|
$new_return_type_parts = [...$new_return_type_parts, ...$parts];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($had_split_values) {
|
$fleshed_out_type = TypeCombiner::combine(
|
||||||
$fleshed_out_type = TypeCombiner::combine(
|
$new_return_type_parts,
|
||||||
$new_return_type_parts,
|
$codebase,
|
||||||
$codebase,
|
);
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$fleshed_out_type = new Union($new_return_type_parts);
|
|
||||||
}
|
|
||||||
|
|
||||||
$fleshed_out_type->from_docblock = $return_type->from_docblock;
|
$fleshed_out_type->from_docblock = $return_type->from_docblock;
|
||||||
$fleshed_out_type->ignore_nullable_issues = $return_type->ignore_nullable_issues;
|
$fleshed_out_type->ignore_nullable_issues = $return_type->ignore_nullable_issues;
|
||||||
|
@ -771,6 +771,38 @@ class TypeAnnotationTest extends TestCase
|
|||||||
'$output===' => 'array{phone: string}',
|
'$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…
x
Reference in New Issue
Block a user