mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #5578 - variables always set in conditionals should be combined
This commit is contained in:
parent
6851b5c1f1
commit
7080bc3bff
@ -368,7 +368,11 @@ class OrAnalyzer
|
||||
$codebase
|
||||
);
|
||||
} elseif (isset($left_context->vars_in_scope[$var_id])) {
|
||||
$if_context->vars_in_scope[$var_id] = $left_context->vars_in_scope[$var_id];
|
||||
$if_context->vars_in_scope[$var_id] = Type::combineUnionTypes(
|
||||
$type,
|
||||
$left_context->vars_in_scope[$var_id],
|
||||
$codebase
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -471,6 +471,21 @@ class AssignmentInConditionalTest extends \Psalm\Tests\TestCase
|
||||
}',
|
||||
'error_message' => 'InvalidReturnStatement',
|
||||
],
|
||||
'assignmentInBranchOfOr' => [
|
||||
'<?php
|
||||
function getPath(): string|object {
|
||||
return rand(0, 1) ? "a" : new stdClass();
|
||||
}
|
||||
|
||||
function foo(string $s) : string {
|
||||
if (($path = $s) || ($path = getPath())) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
return "b";
|
||||
}',
|
||||
'error_message' => 'InvalidReturnStatement',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user