show type of lambda in the repl

This commit is contained in:
Folkert 2020-12-26 21:19:45 +01:00
parent da0f239244
commit 95e0faad30
3 changed files with 24 additions and 10 deletions

View file

@ -131,11 +131,15 @@ pub fn gen_and_eval(src: &[u8], target: Triple, opt_level: OptLevel) -> Result<R
let content = subs.get(main_fn_var).content; let content = subs.get(main_fn_var).content;
let expr_type_str = content_to_string(content.clone(), &subs, home, &interns); let expr_type_str = content_to_string(content.clone(), &subs, home, &interns);
let (_, main_fn_layout) = procedures let (_, main_fn_layout) = match procedures.keys().find(|(s, _)| *s == main_fn_symbol) {
.keys() Some(layout) => layout.clone(),
.find(|(s, _)| *s == main_fn_symbol) None => {
.unwrap() return Ok(ReplOutput::NoProblems {
.clone(); expr: "<function>".to_string(),
expr_type: expr_type_str,
});
}
};
let ptr_bytes = target.pointer_width().unwrap().bytes() as u32; let ptr_bytes = target.pointer_width().unwrap().bytes() as u32;

View file

@ -20,7 +20,7 @@ use roc_module::symbol::{
use roc_mono::ir::{ use roc_mono::ir::{
CapturedSymbols, ExternalSpecializations, PartialProc, PendingSpecialization, Proc, Procs, CapturedSymbols, ExternalSpecializations, PartialProc, PendingSpecialization, Proc, Procs,
}; };
use roc_mono::layout::{Layout, LayoutCache}; use roc_mono::layout::{Layout, LayoutCache, LayoutProblem};
use roc_parse::ast::{self, Attempting, StrLiteral, TypeAnnotation}; use roc_parse::ast::{self, Attempting, StrLiteral, TypeAnnotation};
use roc_parse::header::{ use roc_parse::header::{
ExposesEntry, ImportsEntry, PackageEntry, PackageOrPath, PlatformHeader, To, TypedIdent, ExposesEntry, ImportsEntry, PackageEntry, PackageOrPath, PlatformHeader, To, TypedIdent,
@ -3503,9 +3503,20 @@ fn add_def_to_module<'a>(
mono_env.subs, mono_env.subs,
) { ) {
Ok(l) => l, Ok(l) => l,
Err(err) => { Err(LayoutProblem::Erroneous) => {
// a host-exposed function is not monomorphized let message = "top level function has erroneous type";
todo!("The host-exposed function {:?} does not have a valid layout (e.g. maybe the function wasn't monomorphic): {:?}", symbol, err) 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;
} }
}; };

View file

@ -1508,7 +1508,6 @@ pub fn specialize_all<'a>(
)); ));
procs.runtime_errors.insert(name, error_msg); procs.runtime_errors.insert(name, error_msg);
panic!("failed to specialize {:?}", name);
} }
} }
} }