pub struct Union {
pub types: AtomicVec,
pub possibly_undefined: bool,
pub from_docblock: bool,
}Fields§
§types: AtomicVec§possibly_undefined: boolThe variable holding this type may not be initialized at this point.
from_docblock: boolThis union originated from a docblock annotation rather than inference.
Implementations§
Source§impl Union
impl Union
pub fn empty() -> Self
pub fn single(atomic: Atomic) -> Self
pub fn mixed() -> Self
pub fn void() -> Self
pub fn never() -> Self
pub fn null() -> Self
pub fn bool() -> Self
pub fn int() -> Self
pub fn float() -> Self
pub fn string() -> Self
Sourcepub fn from_vec(atomics: Vec<Atomic>) -> Self
pub fn from_vec(atomics: Vec<Atomic>) -> Self
Build a union from multiple atomics, de-duplicating on the fly.
pub fn is_empty(&self) -> bool
pub fn is_single(&self) -> bool
pub fn is_nullable(&self) -> bool
pub fn is_mixed(&self) -> bool
pub fn is_never(&self) -> bool
pub fn is_void(&self) -> bool
pub fn can_be_falsy(&self) -> bool
pub fn can_be_truthy(&self) -> bool
pub fn contains<F: Fn(&Atomic) -> bool>(&self, f: F) -> bool
pub fn has_named_object(&self, fqcn: &str) -> bool
Sourcepub fn add_type(&mut self, atomic: Atomic)
pub fn add_type(&mut self, atomic: Atomic)
Add an atomic to this union, skipping duplicates. Subsumption rules: anything ⊆ TMixed; TLiteralInt ⊆ TInt; etc.
Sourcepub fn remove_null(&self) -> Union
pub fn remove_null(&self) -> Union
Remove null from the union (e.g. after a null check).
Sourcepub fn remove_false(&self) -> Union
pub fn remove_false(&self) -> Union
Remove false from the union.
Sourcepub fn narrow_to_truthy(&self) -> Union
pub fn narrow_to_truthy(&self) -> Union
Keep only truthy atomics (e.g. after if ($x)).
Sourcepub fn narrow_to_falsy(&self) -> Union
pub fn narrow_to_falsy(&self) -> Union
Keep only falsy atomics (e.g. after if (!$x)).
Sourcepub fn narrow_instanceof(&self, class: &str) -> Union
pub fn narrow_instanceof(&self, class: &str) -> Union
Narrow this type as if $x instanceof ClassName is true.
The instanceof check guarantees the value IS an instance of class, so we
replace any object / mixed constituents with the specific named object. Scalar
constituents are dropped (they can never satisfy instanceof).
Sourcepub fn narrow_to_string(&self) -> Union
pub fn narrow_to_string(&self) -> Union
Narrow as if is_string($x) is true.
Sourcepub fn narrow_to_int(&self) -> Union
pub fn narrow_to_int(&self) -> Union
Narrow as if is_int($x) is true.
Sourcepub fn narrow_to_float(&self) -> Union
pub fn narrow_to_float(&self) -> Union
Narrow as if is_float($x) is true.
Sourcepub fn narrow_to_bool(&self) -> Union
pub fn narrow_to_bool(&self) -> Union
Narrow as if is_bool($x) is true.
Sourcepub fn narrow_to_null(&self) -> Union
pub fn narrow_to_null(&self) -> Union
Narrow as if is_null($x) is true.
Sourcepub fn narrow_to_array(&self) -> Union
pub fn narrow_to_array(&self) -> Union
Narrow as if is_array($x) is true.
Sourcepub fn narrow_to_object(&self) -> Union
pub fn narrow_to_object(&self) -> Union
Narrow as if is_object($x) is true.
Sourcepub fn narrow_to_callable(&self) -> Union
pub fn narrow_to_callable(&self) -> Union
Narrow as if is_callable($x) is true.
Sourcepub fn merge(a: &Union, b: &Union) -> Union
pub fn merge(a: &Union, b: &Union) -> Union
Merge two unions at a branch join point (e.g. after if/else). The result is the union of all types in both.
Sourcepub fn intersect_with(&self, other: &Union) -> Union
pub fn intersect_with(&self, other: &Union) -> Union
Intersect with another union: keep only types present in other, widening
where self contains mixed (which is compatible with everything).
Used for match-arm subject narrowing.
Sourcepub fn substitute_templates(&self, bindings: &HashMap<Arc<str>, Union>) -> Union
pub fn substitute_templates(&self, bindings: &HashMap<Arc<str>, Union>) -> Union
Replace template param references with their resolved types.
Sourcepub fn is_subtype_of_simple(&self, other: &Union) -> bool
pub fn is_subtype_of_simple(&self, other: &Union) -> bool
Returns true if every atomic in self is a subtype of some atomic in other.
Does not require a Codebase (no inheritance check); use the codebase-aware
version in mir-analyzer for full checks.
Sourcepub fn possibly_undefined(self) -> Self
pub fn possibly_undefined(self) -> Self
Mark this union as possibly-undefined and return it.
Sourcepub fn from_docblock(self) -> Self
pub fn from_docblock(self) -> Self
Mark this union as coming from a docblock annotation.