Skip to content

Commit

Permalink
Improve error message for folding with wrong number of arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
01mf02 committed Nov 14, 2024
1 parent 0a93877 commit 760ffda
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion jaq-play/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,14 @@ fn report_parse(code: &str, (expected, found): load::parse::Error<&str>) -> Repo
}

fn report_compile(code: &str, (found, undefined): compile::Error<&str>) -> Report {
use compile::Undefined::Filter;
let found_range = load::span(code, found);
let message = format!("undefined {}", undefined.as_str());
let wnoa = |exp, got| format!("wrong number of arguments (expected {exp}, found {got})");
let message = match (found, undefined) {
("reduce", Filter(arity)) => wnoa("2", arity),
("foreach", Filter(arity)) => wnoa("2 or 3", arity),
(_, undefined) => format!("undefined {}", undefined.as_str()),
};
let found = [(message.clone(), None)].into();

Report {
Expand Down
8 changes: 7 additions & 1 deletion jaq/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,14 @@ fn report_parse(code: &str, (expected, found): load::parse::Error<&str>) -> Repo
}

fn report_compile(code: &str, (found, undefined): compile::Error<&str>) -> Report {
use compile::Undefined::Filter;
let found_range = load::span(code, found);
let message = format!("undefined {}", undefined.as_str());
let wnoa = |exp, got| format!("wrong number of arguments (expected {exp}, found {got})");
let message = match (found, undefined) {
("reduce", Filter(arity)) => wnoa("2", arity),
("foreach", Filter(arity)) => wnoa("2 or 3", arity),
(_, undefined) => format!("undefined {}", undefined.as_str()),
};
let found = [(message.clone(), None)].into();

Report {
Expand Down

0 comments on commit 760ffda

Please sign in to comment.