[fine] Environment cycles are internal compiler errors
Re-work the failure to add official ICE support, and extract the reporting from the tests into the semantics, so everybody benefits.
This commit is contained in:
parent
3877c6e547
commit
2f71946d21
2 changed files with 74 additions and 53 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use fine::parser::{SyntaxTree, TreeRef};
|
||||
use fine::parser::SyntaxTree;
|
||||
use fine::semantics::{Semantics, Type};
|
||||
use fine::tokens::Lines;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
|
@ -85,52 +85,11 @@ fn assert_concrete(tree: &SyntaxTree, expected: &str, source_path: &str) {
|
|||
}
|
||||
}
|
||||
|
||||
fn report_semantic_error(semantics: &Semantics, tr: Option<TreeRef>, message: &str) {
|
||||
let tree = semantics.tree();
|
||||
|
||||
println!("{message}! Parsed the tree as:");
|
||||
println!("\n{}", tree.dump(true));
|
||||
|
||||
let errors = semantics.snapshot_errors();
|
||||
if errors.len() == 0 {
|
||||
println!("There were no errors reported during checking.\n");
|
||||
} else {
|
||||
println!(
|
||||
"{} error{} reported during checking:",
|
||||
errors.len(),
|
||||
if errors.len() == 1 { "" } else { "s" }
|
||||
);
|
||||
for error in &errors {
|
||||
println!(" Error: {error}");
|
||||
}
|
||||
println!();
|
||||
}
|
||||
|
||||
if let Some(tr) = tr {
|
||||
println!("About the tree: {:?}", &tree[tr]);
|
||||
println!("The logical parent chain of the tree was:\n");
|
||||
let mut current = Some(tr);
|
||||
while let Some(c) = current {
|
||||
let t = &tree[c];
|
||||
println!(" {:?} [{}-{})", t.kind, t.start_pos, t.end_pos);
|
||||
current = semantics.logical_parent(c);
|
||||
}
|
||||
println!("\nThe environment of the tree was:");
|
||||
let mut environment = Some(semantics.environment_of(tr));
|
||||
while let Some(env) = environment {
|
||||
for (k, v) in env.declarations.iter() {
|
||||
println!(" {k}: {:?}", v.declaration_type);
|
||||
}
|
||||
environment = env.parent.clone();
|
||||
}
|
||||
println!();
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! semantic_panic {
|
||||
($semantics:expr, $tr:expr, $($t:tt)*) => {{
|
||||
let message = format!($($t)*);
|
||||
report_semantic_error($semantics, $tr, &message);
|
||||
eprintln!("{message}!");
|
||||
$semantics.dump_compiler_state($tr);
|
||||
panic!("{message}");
|
||||
}};
|
||||
}
|
||||
|
|
@ -139,7 +98,8 @@ macro_rules! semantic_assert {
|
|||
($semantics:expr, $tr:expr, $pred:expr, $($t:tt)*) => {{
|
||||
if !$pred {
|
||||
let message = format!($($t)*);
|
||||
report_semantic_error($semantics, $tr, &message);
|
||||
eprintln!("{message}!");
|
||||
$semantics.dump_compiler_state($tr);
|
||||
panic!("{message}");
|
||||
}
|
||||
}};
|
||||
|
|
@ -151,7 +111,8 @@ macro_rules! semantic_assert_eq {
|
|||
let rr = $right;
|
||||
if ll != rr {
|
||||
let message = format!($($t)*);
|
||||
report_semantic_error($semantics, $tr, &message);
|
||||
eprintln!("{message}!");
|
||||
$semantics.dump_compiler_state($tr);
|
||||
assert_eq!(ll, rr, "{}", message);
|
||||
}
|
||||
}};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue