mirror of
https://github.com/danog/ext-php-rs.git
synced 2024-11-30 04:39:04 +01:00
fixes inifinte loop in ClassEntry::instance_of (#188)
This commit is contained in:
parent
3b1e2e3848
commit
4ea01f8d98
@ -37,37 +37,19 @@ impl ClassEntry {
|
||||
///
|
||||
/// # Parameters
|
||||
///
|
||||
/// * `ce` - The inherited class entry to check.
|
||||
pub fn instance_of(&self, ce: &ClassEntry) -> bool {
|
||||
if self == ce {
|
||||
/// * `other` - The inherited class entry to check.
|
||||
pub fn instance_of(&self, other: &ClassEntry) -> bool {
|
||||
if self == other {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ce.flags().contains(ClassFlags::Interface) {
|
||||
let interfaces = match self.interfaces() {
|
||||
Some(interfaces) => interfaces,
|
||||
None => return false,
|
||||
};
|
||||
|
||||
for i in interfaces {
|
||||
if ce == i {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
loop {
|
||||
let parent = match self.parent() {
|
||||
Some(parent) => parent,
|
||||
None => return false,
|
||||
};
|
||||
|
||||
if parent == ce {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if other.is_interface() {
|
||||
return self
|
||||
.interfaces()
|
||||
.map_or(false, |mut it| it.any(|ce| ce == other));
|
||||
}
|
||||
|
||||
false
|
||||
std::iter::successors(self.parent(), |p| p.parent()).any(|ce| ce == other)
|
||||
}
|
||||
|
||||
/// Returns an iterator of all the interfaces that the class implements.
|
||||
|
Loading…
Reference in New Issue
Block a user