From d470903722cfcbc1cd04744c5491d3e6d13ec3d9 Mon Sep 17 00:00:00 2001 From: Brown Date: Mon, 13 Apr 2020 08:47:11 -0400 Subject: [PATCH] Make Algebra::negateFormula a little more safe --- src/Psalm/Type/Algebra.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Type/Algebra.php b/src/Psalm/Type/Algebra.php index 5e1bdb89309..12c85fe6ae9 100644 --- a/src/Psalm/Type/Algebra.php +++ b/src/Psalm/Type/Algebra.php @@ -546,7 +546,7 @@ function ($possible_type) { } /** - * @param array $clauses + * @param non-empty-array $clauses * * @return array */ @@ -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)];