mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +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 std::time::SystemTime;
|
||||||
|
|
||||||
use roc_reporting::report::{
|
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 code_gen_start = SystemTime::now();
|
||||||
let total_problems = loaded.total_problems();
|
|
||||||
let palette = DEFAULT_PALETTE;
|
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 {
|
for (home, (module_path, src)) in loaded.sources {
|
||||||
let mut src_lines: Vec<&str> = Vec::new();
|
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();
|
let problems = loaded.can_problems.remove(&home).unwrap_or_default();
|
||||||
for problem in problems.into_iter() {
|
for problem in problems.into_iter() {
|
||||||
let report = can_problem(&alloc, module_path.clone(), problem);
|
let report = can_problem(&alloc, module_path.clone(), problem);
|
||||||
|
let severity = report.severity;
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
|
|
||||||
report.render_color_terminal(&mut buf, &alloc, &palette);
|
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();
|
let problems = loaded.type_problems.remove(&home).unwrap_or_default();
|
||||||
for problem in problems {
|
for problem in problems {
|
||||||
let report = type_problem(&alloc, module_path.clone(), problem);
|
let report = type_problem(&alloc, module_path.clone(), problem);
|
||||||
|
let severity = report.severity;
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
|
|
||||||
report.render_color_terminal(&mut buf, &alloc, &palette);
|
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();
|
let problems = loaded.mono_problems.remove(&home).unwrap_or_default();
|
||||||
for problem in problems {
|
for problem in problems {
|
||||||
let report = mono_problem(&alloc, module_path.clone(), problem);
|
let report = mono_problem(&alloc, module_path.clone(), problem);
|
||||||
|
let severity = report.severity;
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
|
|
||||||
report.render_color_terminal(&mut buf, &alloc, &palette);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ pub fn cycle<'b>(
|
||||||
.annotate(Annotation::TypeBlock)
|
.annotate(Annotation::TypeBlock)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum Severity {
|
pub enum Severity {
|
||||||
/// This will cause a runtime error if some code get srun
|
/// This will cause a runtime error if some code get srun
|
||||||
/// (e.g. type mismatch, naming error)
|
/// (e.g. type mismatch, naming error)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue