Skip to content

Commit 5024259

Browse files
committed
Support intersection types in arg info
1 parent b56492b commit 5024259

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

build/gen_stub.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ public function toArginfoType(): ArginfoType {
689689
$classTypes[] = $type;
690690
}
691691
}
692-
return new ArginfoType($classTypes, $builtinTypes);
692+
return new ArginfoType($classTypes, $builtinTypes, $this->isIntersection);
693693
}
694694

695695
public function toOptimizerTypeMask(): string {
@@ -784,22 +784,25 @@ class ArginfoType {
784784

785785
/** @var SimpleType[] $builtinTypes */
786786
private $builtinTypes;
787+
private bool $isIntersection;
787788

788789
/**
789790
* @param SimpleType[] $classTypes
790791
* @param SimpleType[] $builtinTypes
791792
*/
792-
public function __construct(array $classTypes, array $builtinTypes) {
793+
public function __construct(array $classTypes, array $builtinTypes, bool $isIntersection) {
793794
$this->classTypes = $classTypes;
794795
$this->builtinTypes = $builtinTypes;
796+
$this->isIntersection = $isIntersection;
795797
}
796798

797799
public function hasClassType(): bool {
798800
return !empty($this->classTypes);
799801
}
800802

801803
public function toClassTypeString(): string {
802-
return implode('|', array_map(function(SimpleType $type) {
804+
$separator = $this->isIntersection ? '&' : '|';
805+
return implode($separator, array_map(function(SimpleType $type) {
803806
return $type->toEscapedName();
804807
}, $this->classTypes));
805808
}
@@ -808,6 +811,7 @@ public function toTypeMask(): string {
808811
if (empty($this->builtinTypes)) {
809812
return '0';
810813
}
814+
/* Intersection types cannot happen with built-in types */
811815
return implode('|', array_map(function(SimpleType $type) {
812816
return $type->toTypeMask();
813817
}, $this->builtinTypes));

0 commit comments

Comments
 (0)