Skip to content

Commit

Permalink
Err out on unknown function (#66)
Browse files Browse the repository at this point in the history
* Err out on unknown function

* Added tests

* Lazily instanciate/bump the Arc
  • Loading branch information
alexsnaps authored Jul 11, 2024
1 parent 18466fa commit 2cb75cb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions interpreter/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ impl<'a> Context<'a> {
.get(&name)
.cloned()
.or_else(|| parent.get_variable(&name).ok())
.ok_or(ExecutionError::UndeclaredReference(name.into())),
.ok_or_else(|| ExecutionError::UndeclaredReference(name.into())),
Context::Root { variables, .. } => variables
.get(&name)
.cloned()
.ok_or(ExecutionError::UndeclaredReference(name.into())),
.ok_or_else(|| ExecutionError::UndeclaredReference(name.into())),
}
}

Expand Down
10 changes: 10 additions & 0 deletions interpreter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,16 @@ mod tests {
"missing == 1",
ExecutionError::undeclared_reference("missing"),
),
(
"undeclared method",
"1.missing()",
ExecutionError::undeclared_reference("missing"),
),
(
"undeclared function",
"missing(1)",
ExecutionError::undeclared_reference("missing"),
),
(
"unsupported key type",
"{null: true}",
Expand Down
4 changes: 3 additions & 1 deletion interpreter/src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,9 @@ impl<'a> Value {
Expression::Ident(name) => ctx.get_variable(&***name),
Expression::FunctionCall(name, target, args) => {
if let Expression::Ident(name) = &**name {
let func = ctx.get_function(&**name).unwrap();
let func = ctx
.get_function(&**name)
.ok_or_else(|| ExecutionError::UndeclaredReference(Arc::clone(name)))?;
match target {
None => {
let mut ctx =
Expand Down

0 comments on commit 2cb75cb

Please sign in to comment.