mirror of
https://github.com/danog/psalm.git
synced 2024-12-04 18:48:03 +01:00
commit
0f275cb25a
@ -497,6 +497,14 @@ class Union implements TypeNode
|
||||
$nullable = true;
|
||||
}
|
||||
|
||||
$falsable = false;
|
||||
|
||||
if (isset($types['false']) && count($types) > 1) {
|
||||
unset($types['false']);
|
||||
|
||||
$falsable = true;
|
||||
}
|
||||
|
||||
$php_types = [];
|
||||
|
||||
foreach ($types as $atomic_type) {
|
||||
@ -515,6 +523,10 @@ class Union implements TypeNode
|
||||
$php_types[] = $php_type;
|
||||
}
|
||||
|
||||
if ($falsable) {
|
||||
return ($nullable ? '?' : '') . implode('|', array_unique($php_types)) . '|false';
|
||||
}
|
||||
|
||||
return ($nullable ? '?' : '') . implode('|', array_unique($php_types));
|
||||
}
|
||||
|
||||
|
@ -713,6 +713,24 @@ class ReturnTypeManipulationTest extends FileManipulationTestCase
|
||||
['MissingReturnType'],
|
||||
false,
|
||||
true,
|
||||
],
|
||||
'OrFalseInReturn' => [
|
||||
'<?php
|
||||
function a() {
|
||||
/** @var false|array $a */
|
||||
$a = false;
|
||||
return $a;
|
||||
}',
|
||||
'<?php
|
||||
function a(): array|false {
|
||||
/** @var false|array $a */
|
||||
$a = false;
|
||||
return $a;
|
||||
}',
|
||||
'8.0',
|
||||
['MissingReturnType'],
|
||||
false,
|
||||
true,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user