Fix Tuple::is_record for empty tuples
Zero-length tuple errored badarg instead of returning false the way
erlang.is_record/2 does.
use std::cmp::Ordering::{self, *};
-use std::convert::{TryFrom, TryInto};
+use std::convert::{Into, TryFrom, TryInto};
#[cfg(test)]
use std::fmt::{self, Debug};
use std::hash::{Hash, Hasher};
@@ -138,16 +138,22 @@ impl Tuple {
pub fn is_record(&self, record_tag: Term, size: Option<Term>) -> exception::Result {
match record_tag.tag() {
Atom => {
- let element = self.element(ZeroBasedIndex(0))?;
+ let tagged = if 0 < self.len() {
+ let element = self[0];
match size {
Some(size_term) => {
let size_usize: usize = size_term.try_into()?;
- Ok(((element == record_tag) & (self.len() == size_usize)).into())
+ (element == record_tag) & (self.len() == size_usize)
}
- None => Ok((element == record_tag).into()),
+ None => element == record_tag,
}
+ } else {
+ false
+ };
+
+ Ok(tagged.into())
}
_ => Err(badarg!()),
}
