mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
repl: show error for partial application
This commit is contained in:
parent
ebe22c9903
commit
a760a41e1f
2 changed files with 43 additions and 3 deletions
|
@ -476,6 +476,26 @@ mod repl_eval {
|
|||
expect_success("Num.abs", "<function> : Num a -> Num a");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn too_few_args() {
|
||||
expect_failure(
|
||||
"Num.add 2",
|
||||
indoc!(
|
||||
r#"
|
||||
── TOO FEW ARGS ────────────────────────────────────────────────────────────────
|
||||
|
||||
The add function expects 2 arguments, but it got only 1:
|
||||
|
||||
4│ Num.add 2
|
||||
^^^^^^^
|
||||
|
||||
Roc does not allow functions to be partially applied. Use a closure to
|
||||
make partial application explicit.
|
||||
"#
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn type_problem() {
|
||||
expect_failure(
|
||||
|
|
|
@ -3548,9 +3548,29 @@ fn add_def_to_module<'a>(
|
|||
// get specialized!
|
||||
if is_exposed {
|
||||
let annotation = def.expr_var;
|
||||
let layout = layout_cache.from_var(mono_env.arena, annotation, mono_env.subs).unwrap_or_else(|err|
|
||||
todo!("TODO gracefully handle the situation where we expose a function to the host which doesn't have a valid layout (e.g. maybe the function wasn't monomorphic): {:?}", err)
|
||||
|
||||
let layout = match layout_cache.from_var(
|
||||
mono_env.arena,
|
||||
annotation,
|
||||
mono_env.subs,
|
||||
) {
|
||||
Ok(l) => l,
|
||||
Err(LayoutProblem::Erroneous) => {
|
||||
let message = "top level function has erroneous type";
|
||||
procs.runtime_errors.insert(symbol, message);
|
||||
return;
|
||||
}
|
||||
Err(LayoutProblem::UnresolvedTypeVar(v)) => {
|
||||
let message = format!(
|
||||
"top level function has unresolved type variable {:?}",
|
||||
v
|
||||
);
|
||||
procs
|
||||
.runtime_errors
|
||||
.insert(symbol, mono_env.arena.alloc(message));
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
procs.insert_exposed(
|
||||
symbol,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue