Skip to content
Permalink
Browse files

Fix #2426, or at least some of it

  • Loading branch information
muglug committed Dec 8, 2019
1 parent 2e00ad2 commit 83b10bb9af4b9a48bb6b22c7f36e4fd54c1ce3e3
@@ -147,6 +147,13 @@ class Context
*/
public $clauses = [];

/**
* A list of hashed clauses that have already been factored in
*
* @var list<string>
*/
public $reconciled_expression_clauses = [];

/**
* Whether or not to do a deep analysis and collect mutations to this context
*
@@ -280,6 +287,16 @@ class Context
*/
public $case_scope = null;

/**
* @var Context|null
*/
public $if_context = null;

/**
* @var \Psalm\Internal\Scope\IfScope|null
*/
public $if_scope = null;

/**
* @var bool
*/
@@ -487,31 +504,62 @@ public function remove($remove_var_id)
}

/**
* This removes all clauses that are invalidated because
* all possibilities are overwritten by changed var ids
*
* @param Clause[] $clauses
* @param array<string, bool> $changed_var_ids
*
* @return void
* @return list<Clause>
*/
public function removeReconciledClauses(array $changed_var_ids)
public static function removeOverwrittenClauses(array $clauses, array $changed_var_ids)
{
$this->clauses = \array_values(
array_filter(
$this->clauses,
/** @return bool */
function (Clause $c) use ($changed_var_ids) {
if ($c->wedge) {
return true;
}
$included_clauses = [];

foreach ($c->possibilities as $key => $_) {
if (isset($changed_var_ids[$key])) {
return false;
}
}
foreach ($clauses as $c) {
if ($c->wedge) {
$included_clauses[] = $c;
continue;
}

return true;
if (!\array_diff_key($c->possibilities, $changed_var_ids)) {
continue;
}

$included_clauses[] = $c;
}

return $included_clauses;
}

/**
* @param Clause[] $clauses
* @param array<string, bool> $changed_var_ids
*
* @return array{0: list<Clause>, list<Clause>}
*/
public static function removeReconciledClauses(array $clauses, array $changed_var_ids)
{
$included_clauses = [];
$rejected_clauses = [];

foreach ($clauses as $c) {
if ($c->wedge) {
$included_clauses[] = $c;
continue;
}

foreach ($c->possibilities as $key => $_) {
if (isset($changed_var_ids[$key])) {
$rejected_clauses[] = $c;
continue 2;
}
)
);
}

$included_clauses[] = $c;
}

return [$included_clauses, $rejected_clauses];
}

/**

0 comments on commit 83b10bb

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