Skip to content

Commit

Permalink
Don’t overwrite true flag
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Oct 19, 2020
1 parent db119d6 commit 9e3b069
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ private static function coerceValueAfterGatekeeperArgument(
}
}

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

Expand Down
27 changes: 27 additions & 0 deletions tests/TypeReconciliation/ConditionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1902,6 +1902,33 @@ function exampleWithOr($value): O {
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 {}
Expand Down

0 comments on commit 9e3b069

Please sign in to comment.