mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Ignore just-coerced vars
This commit is contained in:
parent
b646414304
commit
3c29ffd0b7
@ -1853,6 +1853,13 @@ class IfAnalyzer
|
|||||||
Context $outer_context,
|
Context $outer_context,
|
||||||
array $cond_assigned_var_ids
|
array $cond_assigned_var_ids
|
||||||
) : void {
|
) : void {
|
||||||
|
// this filters out coercions to expeccted types in ArgumentAnalyzer
|
||||||
|
$cond_assigned_var_ids = \array_filter($cond_assigned_var_ids);
|
||||||
|
|
||||||
|
if (!$cond_assigned_var_ids) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$exprs = self::getDefinitelyEvaluatedOredExpressions($cond);
|
$exprs = self::getDefinitelyEvaluatedOredExpressions($cond);
|
||||||
|
|
||||||
// if there was no assignment in the first expression it's safe to proceed
|
// if there was no assignment in the first expression it's safe to proceed
|
||||||
|
@ -1181,7 +1181,7 @@ class ArgumentAnalyzer
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($context->inside_conditional) {
|
if ($context->inside_conditional) {
|
||||||
$context->assigned_var_ids[$var_id] = true;
|
$context->assigned_var_ids[$var_id] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($was_cloned) {
|
if ($was_cloned) {
|
||||||
|
@ -2900,6 +2900,21 @@ class ConditionalTest extends \Psalm\Tests\TestCase
|
|||||||
}
|
}
|
||||||
}'
|
}'
|
||||||
],
|
],
|
||||||
|
'nonRedundantConditionAfterThing' => [
|
||||||
|
'<?php
|
||||||
|
class U {
|
||||||
|
public function takes(self $u) : bool {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function bar(?U $a, ?U $b) : void {
|
||||||
|
if ($a === null
|
||||||
|
|| ($b !== null && $a->takes($b))
|
||||||
|
|| $b === null
|
||||||
|
) {}
|
||||||
|
}'
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user