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:
parent
b7a7e2fb87
commit
2a92025737
@ -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());
|
||||
}
|
||||
|
@ -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'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user