mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Fix null coalescing on nullable output
This commit is contained in:
parent
eee8442af6
commit
5b3531b5a5
@ -1026,7 +1026,20 @@ class ExpressionChecker
|
||||
$lhs_type = null;
|
||||
|
||||
if (isset($stmt->left->inferredType)) {
|
||||
$lhs_type = $stmt->left->inferredType;
|
||||
$if_return_type_reconciled = TypeChecker::reconcileTypes(
|
||||
'!null',
|
||||
$stmt->left->inferredType,
|
||||
'',
|
||||
$statements_checker,
|
||||
new CodeLocation($statements_checker->getSource(), $stmt),
|
||||
$statements_checker->getSuppressedIssues()
|
||||
);
|
||||
|
||||
if ($if_return_type_reconciled === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$lhs_type = $if_return_type_reconciled;
|
||||
}
|
||||
|
||||
if (!$lhs_type || !isset($stmt->right->inferredType)) {
|
||||
|
@ -58,6 +58,17 @@ class Php70Test extends TestCase
|
||||
'$a' => 'string|null',
|
||||
],
|
||||
],
|
||||
'nullCoalesceWithNullableOnLeft' => [
|
||||
'<?php
|
||||
/** @return ?string */
|
||||
function foo() {
|
||||
return rand(0, 10) > 5 ? "hello" : null;
|
||||
}
|
||||
$a = foo() ?? "goodbye";',
|
||||
'assertions' => [
|
||||
'$a' => 'string',
|
||||
],
|
||||
],
|
||||
'nullCoalesceWithReference' => [
|
||||
'<?php
|
||||
$var = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user