mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +00:00
Only print warnings if there are no errors
This commit is contained in:
parent
69bafb4e17
commit
3364ea00e0
2 changed files with 47 additions and 6 deletions
|
@ -42,13 +42,19 @@ pub fn gen_from_mono_module(
|
|||
use std::time::SystemTime;
|
||||
|
||||
use roc_reporting::report::{
|
||||
can_problem, mono_problem, type_problem, Report, RocDocAllocator, DEFAULT_PALETTE,
|
||||
can_problem, mono_problem, type_problem, Report, RocDocAllocator, Severity::*,
|
||||
DEFAULT_PALETTE,
|
||||
};
|
||||
|
||||
let code_gen_start = SystemTime::now();
|
||||
let total_problems = loaded.total_problems();
|
||||
let palette = DEFAULT_PALETTE;
|
||||
|
||||
// This will often over-allocate total memory, but it means we definitely
|
||||
// never need to re-allocate either the warnings or the errors vec!
|
||||
let total_problems = loaded.total_problems();
|
||||
let mut warnings = Vec::with_capacity(total_problems);
|
||||
let mut errors = Vec::with_capacity(total_problems);
|
||||
|
||||
for (home, (module_path, src)) in loaded.sources {
|
||||
let mut src_lines: Vec<&str> = Vec::new();
|
||||
|
||||
|
@ -65,31 +71,66 @@ pub fn gen_from_mono_module(
|
|||
let problems = loaded.can_problems.remove(&home).unwrap_or_default();
|
||||
for problem in problems.into_iter() {
|
||||
let report = can_problem(&alloc, module_path.clone(), problem);
|
||||
let severity = report.severity;
|
||||
let mut buf = String::new();
|
||||
|
||||
report.render_color_terminal(&mut buf, &alloc, &palette);
|
||||
|
||||
println!("\n{}\n", buf);
|
||||
match severity {
|
||||
Warning => {
|
||||
warnings.push(buf);
|
||||
}
|
||||
RuntimeError => {
|
||||
errors.push(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let problems = loaded.type_problems.remove(&home).unwrap_or_default();
|
||||
for problem in problems {
|
||||
let report = type_problem(&alloc, module_path.clone(), problem);
|
||||
let severity = report.severity;
|
||||
let mut buf = String::new();
|
||||
|
||||
report.render_color_terminal(&mut buf, &alloc, &palette);
|
||||
|
||||
println!("\n{}\n", buf);
|
||||
match severity {
|
||||
Warning => {
|
||||
warnings.push(buf);
|
||||
}
|
||||
RuntimeError => {
|
||||
errors.push(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let problems = loaded.mono_problems.remove(&home).unwrap_or_default();
|
||||
for problem in problems {
|
||||
let report = mono_problem(&alloc, module_path.clone(), problem);
|
||||
let severity = report.severity;
|
||||
let mut buf = String::new();
|
||||
|
||||
report.render_color_terminal(&mut buf, &alloc, &palette);
|
||||
|
||||
println!("\n{}\n", buf);
|
||||
match severity {
|
||||
Warning => {
|
||||
warnings.push(buf);
|
||||
}
|
||||
RuntimeError => {
|
||||
errors.push(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Only print warnings if there are no errors
|
||||
if errors.is_empty() {
|
||||
for warning in warnings {
|
||||
println!("\n{}\n", warning);
|
||||
}
|
||||
} else {
|
||||
for error in errors {
|
||||
println!("\n{}\n", error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue