mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix #959 - allow nullable followed by parentheses
This commit is contained in:
parent
17ea48eda4
commit
7dd3273a62
@ -387,18 +387,23 @@ abstract class Type
|
||||
}
|
||||
|
||||
if ($parse_tree instanceof ParseTree\NullableTree) {
|
||||
$atomic_type = self::getTypeFromTree($parse_tree->children[0], false, $template_type_names);
|
||||
$non_nullable_type = self::getTypeFromTree($parse_tree->children[0], false, $template_type_names);
|
||||
|
||||
if (!$atomic_type instanceof Atomic) {
|
||||
throw new \UnexpectedValueException(
|
||||
'Was expecting an atomic type, got ' . get_class($atomic_type)
|
||||
);
|
||||
if ($non_nullable_type instanceof Union) {
|
||||
$non_nullable_type->addType(new TNull);
|
||||
return $non_nullable_type;
|
||||
}
|
||||
|
||||
return TypeCombination::combineTypes([
|
||||
new TNull,
|
||||
$atomic_type
|
||||
]);
|
||||
if ($non_nullable_type instanceof Atomic) {
|
||||
return TypeCombination::combineTypes([
|
||||
new TNull,
|
||||
$non_nullable_type
|
||||
]);
|
||||
}
|
||||
|
||||
throw new \UnexpectedValueException(
|
||||
'Was expecting an atomic or union type, got ' . get_class($non_nullable_type)
|
||||
);
|
||||
}
|
||||
|
||||
if (!$parse_tree instanceof ParseTree\Value) {
|
||||
|
@ -61,6 +61,14 @@ class TypeParseTest extends TestCase
|
||||
$this->assertSame('null|string', (string) Type::parseString('?string'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testNullableUnion()
|
||||
{
|
||||
$this->assertSame('string|int|null', (string) Type::parseString('?(string|int)'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user