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 core_type(&self) -> Union
pub fn core_type(&self) -> Union
Remove both null and false from the union (core type without nullable/falsy variants).
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 narrow_to_scalar(&self) -> Union
pub fn narrow_to_scalar(&self) -> Union
Narrow as if is_scalar($x) is true (int | string | float | bool).
Sourcepub fn narrow_to_iterable(&self) -> Union
pub fn narrow_to_iterable(&self) -> Union
Narrow as if is_iterable($x) is true (array | Traversable).
For simplicity, this narrows to arrays or objects (can’t easily verify interfaces).
Sourcepub fn narrow_to_countable(&self) -> Union
pub fn narrow_to_countable(&self) -> Union
Narrow as if is_countable($x) is true (array | Countable).
For simplicity, this narrows to arrays or objects (can’t easily verify Countable interface).
Sourcepub fn narrow_to_resource(&self) -> Union
pub fn narrow_to_resource(&self) -> Union
Narrow as if is_resource($x) is true.
Note: No TResource atomic type exists in the type system; this is a no-op.
Resources are declining in modern PHP and not actively tracked.
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.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Union
impl<'de> Deserialize<'de> for Union
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Union
impl StructuralPartialEq for Union
Auto Trait Implementations§
impl Freeze for Union
impl RefUnwindSafe for Union
impl Send for Union
impl Sync for Union
impl Unpin for Union
impl UnsafeUnpin for Union
impl UnwindSafe for Union
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.