diff --git a/src/Analyser/ExpressionTypeHolder.php b/src/Analyser/ExpressionTypeHolder.php index 1be893b4bd..3367a640c9 100644 --- a/src/Analyser/ExpressionTypeHolder.php +++ b/src/Analyser/ExpressionTypeHolder.php @@ -34,23 +34,26 @@ public function equals(self $other): bool return false; } - return $this->type->equals($other->type); + return $this->type === $other->type || $this->type->equals($other->type); } public function and(self $other): self { if ($this->type === $other->type || $this->type->equals($other->type)) { - if ($this->certainty->equals($other->certainty)) { + if ($this->certainty->and($other->certainty)->yes()) { return $this; } - $type = $this->type; - } else { - $type = TypeCombinator::union($this->type, $other->type); + if ($this->certainty->maybe()) { + return $this; + } + + return $other; } + return new self( $this->expr, - $type, + TypeCombinator::union($this->type, $other->type), $this->certainty->and($other->certainty), ); }