Skip to content

Commit

Permalink
Make Algebra::negateFormula a little more safe
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Apr 13, 2020
1 parent a25610c commit d470903
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Psalm/Type/Algebra.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ function ($possible_type) {
}

/**
* @param array<int, Clause> $clauses
* @param non-empty-array<int, Clause> $clauses
*
* @return array<int, Clause>
*/
Expand Down Expand Up @@ -759,11 +759,21 @@ public static function combineOredClauses(array $left_clauses, array $right_clau
*/
public static function negateFormula(array $clauses)
{
if (!$clauses) {
return [new Clause([], true)];
}

foreach ($clauses as $clause) {
self::calculateNegation($clause);
}

$negated = self::simplifyCNF(self::groupImpossibilities($clauses));
$impossible_clauses = self::groupImpossibilities($clauses);

if (!$impossible_clauses) {
return [new Clause([], true)];
}

$negated = self::simplifyCNF($impossible_clauses);

if (!$negated) {
return [new Clause([], true)];
Expand Down

0 comments on commit d470903

Please sign in to comment.