1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Union types if stmt already has one

This commit is contained in:
Matt Brown 2020-12-10 01:40:20 -05:00
parent b7a7e2fb87
commit 2a92025737
2 changed files with 18 additions and 4 deletions

View File

@ -566,7 +566,14 @@ class AtomicPropertyFetchAnalyzer
$statements_analyzer->node_data = $old_data_provider;
if ($fake_method_call_type) {
$statements_analyzer->node_data->setType($stmt, $fake_method_call_type);
if ($stmt_type = $statements_analyzer->node_data->getType($stmt)) {
$statements_analyzer->node_data->setType(
$stmt,
Type::combineUnionTypes($fake_method_call_type, $stmt_type)
);
} else {
$statements_analyzer->node_data->setType($stmt, $fake_method_call_type);
}
} else {
$statements_analyzer->node_data->setType($stmt, Type::getMixed());
}

View File

@ -2349,9 +2349,16 @@ class PropertyTypeTest extends TestCase
public string $name = "Dave";
}
function takesNullableUser(User|NullObject $user) : void {
echo $user->name;
}'
function takesNullableUser(User|NullObject $user) : ?string {
$name = $user->name;
if ($name === null) {}
return $name;
}',
[],
[],
'8.0'
],
];
}