panic on wrong number of args to functions
This commit is contained in:
parent
23298c8538
commit
ffe5d2ad61
15
src/value.rs
15
src/value.rs
|
@ -45,6 +45,13 @@ impl LFn {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn accepts(&self, arity: u8) -> bool {
|
||||
match self {
|
||||
LFn::Defined { chunks, .. } => chunks.iter().any(|(a, _)| *a == arity),
|
||||
LFn::Declared { .. } => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &'static str {
|
||||
match self {
|
||||
LFn::Declared { name } | LFn::Defined { name, .. } => name,
|
||||
|
@ -52,7 +59,6 @@ impl LFn {
|
|||
}
|
||||
|
||||
pub fn chunk(&self, arity: u8) -> &Chunk {
|
||||
// println!("Getting chunk of {arity} from {:?}", self);
|
||||
match self {
|
||||
LFn::Declared { .. } => unreachable!(),
|
||||
LFn::Defined { chunks, .. } => &chunks.iter().find(|(a, _)| *a == arity).unwrap().1,
|
||||
|
@ -268,4 +274,11 @@ impl Value {
|
|||
Partial(..) => "fn",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_fn(&self) -> &LFn {
|
||||
match self {
|
||||
Value::Fn(inner) => inner.as_ref(),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user