give better debug info for unresolved type variables

This commit is contained in:
Folkert 2020-11-12 22:28:58 +01:00
parent 4b5a26ebc6
commit a431af660d
3 changed files with 34 additions and 7 deletions

View file

@ -315,7 +315,10 @@ impl<'a> Layout<'a> {
match content {
FlexVar(_) | RigidVar(_) => Err(LayoutProblem::UnresolvedTypeVar(var)),
RecursionVar { .. } => todo!("recursion var"),
RecursionVar { structure, .. } => {
let structure_content = env.subs.get_without_compacting(structure).content;
Self::new_help(env, structure, structure_content)
}
Structure(flat_type) => layout_from_flat_type(env, flat_type),
Alias(Symbol::NUM_INT, args, _) => {
@ -751,7 +754,7 @@ fn layout_from_flat_type<'a>(
// Determine the layouts of the fields, maintaining sort order
let mut layouts = Vec::with_capacity_in(sorted_fields.len(), arena);
for (_, field) in sorted_fields {
for (label, field) in sorted_fields {
use LayoutProblem::*;
let field_var = {
@ -776,7 +779,14 @@ fn layout_from_flat_type<'a>(
layouts.push(layout);
}
}
Err(UnresolvedTypeVar(_)) | Err(Erroneous) => {
Err(UnresolvedTypeVar(v)) => {
// Invalid field!
panic!(
r"I hit an unresolved type var {:?} when determining the layout of {:?} of record field: {:?} : {:?}",
field_var, v, label, field
);
}
Err(Erroneous) => {
// Invalid field!
panic!("TODO gracefully handle record with invalid field.var");
}