From 1789cf05f724b774a7b7525bc939fc9cf6ec1bd5 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 22 Jan 2026 11:13:44 +0100 Subject: [PATCH 1/2] ExpressionTypeHolder: re-use objects more often --- src/Analyser/ExpressionTypeHolder.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Analyser/ExpressionTypeHolder.php b/src/Analyser/ExpressionTypeHolder.php index 1be893b4bd..478aecf3fe 100644 --- a/src/Analyser/ExpressionTypeHolder.php +++ b/src/Analyser/ExpressionTypeHolder.php @@ -34,23 +34,27 @@ 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)) { + $certainty = $this->certainty->and($other->certainty); + if ($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), ); } From 18a339b28f7e8cee7352673a4c8a785ab5f8f733 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 22 Jan 2026 11:53:43 +0100 Subject: [PATCH 2/2] Fix build --- src/Analyser/ExpressionTypeHolder.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Analyser/ExpressionTypeHolder.php b/src/Analyser/ExpressionTypeHolder.php index 478aecf3fe..3367a640c9 100644 --- a/src/Analyser/ExpressionTypeHolder.php +++ b/src/Analyser/ExpressionTypeHolder.php @@ -40,8 +40,7 @@ public function equals(self $other): bool public function and(self $other): self { if ($this->type === $other->type || $this->type->equals($other->type)) { - $certainty = $this->certainty->and($other->certainty); - if ($certainty->yes()) { + if ($this->certainty->and($other->certainty)->yes()) { return $this; }