improve error reporting by mismatch! macro

This commit is contained in:
Folkert 2020-03-13 13:05:47 +01:00
parent a7af366c3a
commit e01a6bab9b

View file

@ -19,6 +19,45 @@ macro_rules! mismatch {
} }
vec![Mismatch::TypeMismatch] vec![Mismatch::TypeMismatch]
}}; }};
($msg:expr) => {{
if cfg!(debug_assertions) {
println!(
"Mismatch in {} Line {} Column {}",
file!(),
line!(),
column!()
);
}
println!($msg);
println!("");
vec![Mismatch::TypeMismatch]
}};
($msg:expr,) => {{
if cfg!(debug_assertions) {
println!(
"Mismatch in {} Line {} Column {}",
file!(),
line!(),
column!()
);
}
println!($msg);
println!("");
vec![Mismatch::TypeMismatch]
}};
($msg:expr, $($arg:tt)*) => {{
if cfg!(debug_assertions) {
println!(
"Mismatch in {} Line {} Column {}",
file!(),
line!(),
column!()
);
}
println!($msg, $($arg)*);
println!("");
vec![Mismatch::TypeMismatch]
}};
} }
type Pool = Vec<Variable>; type Pool = Vec<Variable>;
@ -154,9 +193,9 @@ fn unify_structure(
} }
} }
} }
RigidVar(_) => { RigidVar(name) => {
// Type mismatch! Rigid can only unify with flex. // Type mismatch! Rigid can only unify with flex.
mismatch!() mismatch!("trying to unify {:?} with rigid var {:?}", &flat_type, name)
} }
Structure(ref other_flat_type) => { Structure(ref other_flat_type) => {
@ -552,11 +591,11 @@ fn unify_flat_type(
problems problems
} }
} }
(_other1, _other2) => { (other1, other2) => mismatch!(
// Can't unify other1 and other2 "Trying to two flat types that are incompatible: {:?} ~ {:?}",
// dbg!(&_other1, &_other2); other1,
mismatch!() other2
} ),
} }
} }