mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
parent
57cd29ee9d
commit
578e65820a
@ -513,7 +513,7 @@ class Context
|
|||||||
* @param Clause[] $clauses
|
* @param Clause[] $clauses
|
||||||
* @param array<string, bool> $changed_var_ids
|
* @param array<string, bool> $changed_var_ids
|
||||||
*
|
*
|
||||||
* @return array{0: list<Clause>, list<Clause>}
|
* @return array{list<Clause>, list<Clause>}
|
||||||
*
|
*
|
||||||
* @psalm-pure
|
* @psalm-pure
|
||||||
*/
|
*/
|
||||||
|
@ -250,6 +250,9 @@ class OrAnalyzer
|
|||||||
$pre_referenced_var_ids = $right_context->referenced_var_ids;
|
$pre_referenced_var_ids = $right_context->referenced_var_ids;
|
||||||
$right_context->referenced_var_ids = [];
|
$right_context->referenced_var_ids = [];
|
||||||
|
|
||||||
|
$pre_assigned_var_ids = $right_context->assigned_var_ids;
|
||||||
|
$right_context->assigned_var_ids = [];
|
||||||
|
|
||||||
if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->right, $right_context) === false) {
|
if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->right, $right_context) === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -257,6 +260,9 @@ class OrAnalyzer
|
|||||||
$right_referenced_var_ids = $right_context->referenced_var_ids;
|
$right_referenced_var_ids = $right_context->referenced_var_ids;
|
||||||
$right_context->referenced_var_ids = array_merge($pre_referenced_var_ids, $right_referenced_var_ids);
|
$right_context->referenced_var_ids = array_merge($pre_referenced_var_ids, $right_referenced_var_ids);
|
||||||
|
|
||||||
|
$right_assigned_var_ids = $right_context->assigned_var_ids;
|
||||||
|
$right_context->assigned_var_ids = array_merge($pre_assigned_var_ids, $right_assigned_var_ids);
|
||||||
|
|
||||||
$right_cond_id = \spl_object_id($stmt->right);
|
$right_cond_id = \spl_object_id($stmt->right);
|
||||||
|
|
||||||
$right_clauses = FormulaGenerator::getFormula(
|
$right_clauses = FormulaGenerator::getFormula(
|
||||||
@ -268,6 +274,11 @@ class OrAnalyzer
|
|||||||
$codebase
|
$codebase
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$clauses_for_right_analysis = Context::removeReconciledClauses(
|
||||||
|
$clauses_for_right_analysis,
|
||||||
|
$right_assigned_var_ids
|
||||||
|
)[0];
|
||||||
|
|
||||||
$combined_right_clauses = Algebra::simplifyCNF(
|
$combined_right_clauses = Algebra::simplifyCNF(
|
||||||
array_merge($clauses_for_right_analysis, $right_clauses)
|
array_merge($clauses_for_right_analysis, $right_clauses)
|
||||||
);
|
);
|
||||||
|
@ -430,6 +430,25 @@ class AssignmentInConditionalTest extends \Psalm\Tests\TestCase
|
|||||||
echo $a;
|
echo $a;
|
||||||
}',
|
}',
|
||||||
],
|
],
|
||||||
|
'assignmentInBranchWithReference' => [
|
||||||
|
'<?php
|
||||||
|
class A {}
|
||||||
|
|
||||||
|
function getAOrFalse(bool $b) : A|false {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function foo(A|false $a): void
|
||||||
|
{
|
||||||
|
if ($a instanceof A
|
||||||
|
|| ($a = getAOrFalse($a))
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}',
|
||||||
|
[],
|
||||||
|
[],
|
||||||
|
'8.0'
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user