mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
improve error reporting by mismatch! macro
This commit is contained in:
parent
a7af366c3a
commit
e01a6bab9b
1 changed files with 46 additions and 7 deletions
|
@ -19,6 +19,45 @@ macro_rules! mismatch {
|
|||
}
|
||||
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>;
|
||||
|
@ -154,9 +193,9 @@ fn unify_structure(
|
|||
}
|
||||
}
|
||||
}
|
||||
RigidVar(_) => {
|
||||
RigidVar(name) => {
|
||||
// Type mismatch! Rigid can only unify with flex.
|
||||
mismatch!()
|
||||
mismatch!("trying to unify {:?} with rigid var {:?}", &flat_type, name)
|
||||
}
|
||||
|
||||
Structure(ref other_flat_type) => {
|
||||
|
@ -552,11 +591,11 @@ fn unify_flat_type(
|
|||
problems
|
||||
}
|
||||
}
|
||||
(_other1, _other2) => {
|
||||
// Can't unify other1 and other2
|
||||
// dbg!(&_other1, &_other2);
|
||||
mismatch!()
|
||||
}
|
||||
(other1, other2) => mismatch!(
|
||||
"Trying to two flat types that are incompatible: {:?} ~ {:?}",
|
||||
other1,
|
||||
other2
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue