1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Don’t overwrite true flag

This commit is contained in:
Matt Brown 2020-10-18 01:24:36 -04:00 committed by Daniil Gentili
parent 3cab29ec4e
commit 481cf84b94
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 28 additions and 1 deletions

View File

@ -1180,7 +1180,7 @@ class ArgumentAnalyzer
$input_type->by_ref = $by_ref;
}
if ($context->inside_conditional) {
if ($context->inside_conditional && !isset($context->assigned_var_ids[$var_id])) {
$context->assigned_var_ids[$var_id] = false;
}

View File

@ -1902,6 +1902,33 @@ class ConditionalTest extends \Psalm\Tests\TestCase
return $value;
}'
],
'assertVarRedefinedInIfWithOrAndConversion' => [
'<?php
interface Convertor {
function maybeConvert(string $value): ?SomeObject;
}
interface SomeObject
{
function isValid(): bool;
}
/**
* @param mixed $value
*/
function exampleWithOr(Convertor $convertor, $value): SomeObject
{
if (
!\is_string($value)
|| ($value = $convertor->maybeConvert($value)) === null
|| !$value->isValid()
) {
throw new Exception();
}
return $value;
}'
],
'assertVarRedefinedInIfWithExtraIf' => [
'<?php
class O {}