Skip to content

Commit

Permalink
Revert "Inline possibly_undefined checks"
Browse files Browse the repository at this point in the history
This reverts commit e2a0167.

This change was short-sighted
  • Loading branch information
muglug committed Dec 24, 2021
1 parent e2a0167 commit 75e4e0b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/Psalm/Internal/Type/SimpleAssertionReconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2238,10 +2238,9 @@ private static function reconcileFalsyOrEmpty(
//if any atomic in the union is either always truthy, we remove it. If not always falsy, we mark the check
//as not redundant.
$union = new Union([$existing_var_type_part]);
if (!$existing_var_type->possibly_undefined
&& !$existing_var_type->possibly_undefined_from_try
&& $union->isAlwaysTruthy()
) {
$union->possibly_undefined = $existing_var_type->possibly_undefined;
$union->possibly_undefined_from_try = $existing_var_type->possibly_undefined_from_try;
if ($union->isAlwaysTruthy()) {
$did_remove_type = true;
$existing_var_type->removeType($existing_var_type_key);
} elseif (!$union->isAlwaysFalsy()) {
Expand Down
7 changes: 3 additions & 4 deletions src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,13 +591,12 @@ private static function reconcileFalsyOrEmpty(
//if any atomic in the union is either always falsy, we remove it. If not always truthy, we mark the check
//as not redundant.
$union = new Union([$existing_var_type_part]);
$union->possibly_undefined = $existing_var_type->possibly_undefined;
$union->possibly_undefined_from_try = $existing_var_type->possibly_undefined_from_try;
if ($union->isAlwaysFalsy()) {
$did_remove_type = true;
$existing_var_type->removeType($existing_var_type_key);
} elseif ($existing_var_type->possibly_undefined
|| $existing_var_type->possibly_undefined_from_try
|| !$union->isAlwaysTruthy()
) {
} elseif (!$union->isAlwaysTruthy()) {
$did_remove_type = true;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/Psalm/Type/Union.php
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,10 @@ public function isTrue(): bool

public function isAlwaysTruthy(): bool
{
if ($this->possibly_undefined || $this->possibly_undefined_from_try) {
return false;
}

foreach ($this->getAtomicTypes() as $atomic_type) {
if ($atomic_type instanceof TTrue) {
continue;
Expand Down

0 comments on commit 75e4e0b

Please sign in to comment.