Skip to content

Commit d532879

Browse files
authored
ExpressionTypeHolder: re-use objects more often
1 parent 16cf288 commit d532879

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

‎src/Analyser/ExpressionTypeHolder.php‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,26 @@ public function equals(self $other): bool
3434
return false;
3535
}
3636

37-
return $this->type->equals($other->type);
37+
return $this->type === $other->type || $this->type->equals($other->type);
3838
}
3939

4040
public function and(self $other): self
4141
{
4242
if ($this->type === $other->type || $this->type->equals($other->type)) {
43-
if ($this->certainty->equals($other->certainty)) {
43+
if ($this->certainty->and($other->certainty)->yes()) {
4444
return $this;
4545
}
4646

47-
$type = $this->type;
48-
} else {
49-
$type = TypeCombinator::union($this->type, $other->type);
47+
if ($this->certainty->maybe()) {
48+
return $this;
49+
}
50+
51+
return $other;
5052
}
53+
5154
return new self(
5255
$this->expr,
53-
$type,
56+
TypeCombinator::union($this->type, $other->type),
5457
$this->certainty->and($other->certainty),
5558
);
5659
}

0 commit comments

Comments
 (0)