generate more runtime errors

This commit is contained in:
Folkert 2020-12-26 21:30:25 +01:00
parent 3d1824c658
commit 12c7b5435a
2 changed files with 22 additions and 6 deletions

View file

@ -469,6 +469,13 @@ mod repl_eval {
expect_success("\\x -> x", "<function> : a -> a"); expect_success("\\x -> x", "<function> : a -> a");
} }
#[test]
fn stdlib_function() {
// Even though this gets unwrapped at runtime, the repl should still
// report it as a record
expect_success("Num.abs", "<function> : Num a -> Num a");
}
#[test] #[test]
fn type_problem() { fn type_problem() {
expect_failure( expect_failure(

View file

@ -4868,9 +4868,7 @@ fn reuse_function_symbol<'a>(
// this symbol is a function, that is used by-name (e.g. as an argument to another // this symbol is a function, that is used by-name (e.g. as an argument to another
// function). Register it with the current variable, then create a function pointer // function). Register it with the current variable, then create a function pointer
// to it in the IR. // to it in the IR.
let layout = layout_cache let res_layout = layout_cache.from_var(env.arena, arg_var, env.subs);
.from_var(env.arena, arg_var, env.subs)
.expect("creating layout does not fail");
// we have three kinds of functions really. Plain functions, closures by capture, // we have three kinds of functions really. Plain functions, closures by capture,
// and closures by unification. Here we record whether this function captures // and closures by unification. Here we record whether this function captures
@ -4878,8 +4876,8 @@ fn reuse_function_symbol<'a>(
let captures = partial_proc.captured_symbols.captures(); let captures = partial_proc.captured_symbols.captures();
let captured = partial_proc.captured_symbols.clone(); let captured = partial_proc.captured_symbols.clone();
match layout { match res_layout {
Layout::Closure(argument_layouts, closure_layout, ret_layout) if captures => { Ok(Layout::Closure(argument_layouts, closure_layout, ret_layout)) if captures => {
// this is a closure by capture, meaning it itself captures local variables. // this is a closure by capture, meaning it itself captures local variables.
// we've defined the closure as a (function_ptr, closure_data) pair already // we've defined the closure as a (function_ptr, closure_data) pair already
@ -4957,7 +4955,7 @@ fn reuse_function_symbol<'a>(
stmt stmt
} }
_ => { Ok(layout) => {
procs.insert_passed_by_name( procs.insert_passed_by_name(
env, env,
arg_var, arg_var,
@ -4973,6 +4971,17 @@ fn reuse_function_symbol<'a>(
env.arena.alloc(result), env.arena.alloc(result),
) )
} }
Err(LayoutProblem::Erroneous) => {
let message = format!("The {:?} symbol has an erroneous type", symbol);
Stmt::RuntimeError(env.arena.alloc(message))
}
Err(LayoutProblem::UnresolvedTypeVar(v)) => {
let message = format!(
"The {:?} symbol contains a unresolved type var {:?}",
symbol, v
);
Stmt::RuntimeError(env.arena.alloc(message))
}
} }
} }
} }