Skip to content
Permalink
Browse files

Fix #2459 - don’t add assertions to parent context unnecessarily

  • Loading branch information
muglug committed Dec 12, 2019
1 parent 05783eb commit 8f25183784fd036bc634df34d1d3fcf32e389b45
@@ -253,6 +253,7 @@ function ($c) {

$left_context = clone $context;
$left_context->parent_context = $context;
$left_context->if_context = null;
$left_context->assigned_var_ids = [];

if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->left, $left_context) === false) {
@@ -210,7 +210,9 @@ function ($c) use ($reconciled_expression_clauses) {
$context->vars_in_scope[$var_id],
$type
);
} elseif (isset($if_context->vars_in_scope[$var_id])) {
} elseif (isset($if_context->vars_in_scope[$var_id])
&& isset($if_context->assigned_var_ids[$var_id])
) {
$context->vars_in_scope[$var_id] = Type::combineUnionTypes(
$if_context->vars_in_scope[$var_id],
$type
@@ -691,6 +691,16 @@ public static function combineOredClauses(array $left_clauses, array $right_clau
}
}

foreach ($possibilities as $var_possibilities) {
if (count($var_possibilities) === 2) {
if ($var_possibilities[0] === '!' . $var_possibilities[1]
|| $var_possibilities[1] === '!' . $var_possibilities[0]
) {
continue 2;
}
}
}

$clauses[] = new Clause(
$possibilities,
false,
@@ -2269,6 +2269,24 @@ public static function foo(string $id) : ?string {
}
}',
],
'issetTwice' => [
'<?php
class B {
public function foo() : bool {
return true;
}
}
/** @param array<int, B> $p */
function foo(array $p, int $id) : void {
if ((isset($p[$id]) && rand(0, 1))
|| (!isset($p[$id]) && rand(0, 1))
) {
isset($p[$id]) ? $p[$id] : new B;
isset($p[$id]) ? $p[$id]->foo() : "bar";
}
}'
],
];
}

@@ -1141,6 +1141,21 @@ function foo(string $a, string $b): void {
echo $array["other"];',
'error_message' => 'InvalidArrayOffset',
],
'allEventualitiesMet' => [
'<?php
function resize(bool $landscape, bool $crop) : int {
if (($landscape && $crop) || (!$landscape && !$crop)) {
return 100;
}
if ((!$landscape && $crop) || ($landscape && !$crop)) {
return 50;
}
throw new \UnexpectedValueException("bad");
}',
'error_message' => 'ParadoxicalCondition'
],
];
}
}

0 comments on commit 8f25183

Please sign in to comment.
You can’t perform that action at this time.