Skip to content

Commit 9e3b069

Browse files
committed
Don’t overwrite true flag
1 parent db119d6 commit 9e3b069

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ private static function coerceValueAfterGatekeeperArgument(
11661166
}
11671167
}
11681168

1169-
if ($context->inside_conditional) {
1169+
if ($context->inside_conditional && !isset($context->assigned_var_ids[$var_id])) {
11701170
$context->assigned_var_ids[$var_id] = false;
11711171
}
11721172

tests/TypeReconciliation/ConditionalTest.php

+27
Original file line numberDiff line numberDiff line change
@@ -1902,6 +1902,33 @@ function exampleWithOr($value): O {
19021902
return $value;
19031903
}'
19041904
],
1905+
'assertVarRedefinedInIfWithOrAndConversion' => [
1906+
'<?php
1907+
interface Convertor {
1908+
function maybeConvert(string $value): ?SomeObject;
1909+
}
1910+
1911+
interface SomeObject
1912+
{
1913+
function isValid(): bool;
1914+
}
1915+
1916+
/**
1917+
* @param mixed $value
1918+
*/
1919+
function exampleWithOr(Convertor $convertor, $value): SomeObject
1920+
{
1921+
if (
1922+
!\is_string($value)
1923+
|| ($value = $convertor->maybeConvert($value)) === null
1924+
|| !$value->isValid()
1925+
) {
1926+
throw new Exception();
1927+
}
1928+
1929+
return $value;
1930+
}'
1931+
],
19051932
'assertVarRedefinedInIfWithExtraIf' => [
19061933
'<?php
19071934
class O {}

0 commit comments

Comments
 (0)