Ignore type errors that have already been reported

This commit is contained in:
Richard Feldman 2021-09-18 02:47:39 -04:00
parent cde9f97415
commit a21ad7064c
6 changed files with 48 additions and 37 deletions

View file

@ -107,13 +107,14 @@ pub fn gen_and_eval<'a>(
}
for problem in type_problems {
let report = type_problem(&alloc, module_path.clone(), problem);
if let Some(report) = type_problem(&alloc, module_path.clone(), problem) {
let mut buf = String::new();
report.render_color_terminal(&mut buf, &alloc, &palette);
lines.push(buf);
}
}
for problem in mono_problems {
let report = mono_problem(&alloc, module_path.clone(), problem);

View file

@ -74,7 +74,7 @@ pub fn report_problems(loaded: &mut MonomorphizedModule) -> usize {
let problems = loaded.type_problems.remove(home).unwrap_or_default();
for problem in problems {
let report = type_problem(&alloc, module_path.clone(), problem);
if let Some(report) = type_problem(&alloc, module_path.clone(), problem) {
let severity = report.severity;
let mut buf = String::new();
@ -89,6 +89,7 @@ pub fn report_problems(loaded: &mut MonomorphizedModule) -> usize {
}
}
}
}
let problems = loaded.mono_problems.remove(home).unwrap_or_default();

View file

@ -145,13 +145,14 @@ pub fn helper<'a>(
}
for problem in type_problems {
let report = type_problem(&alloc, module_path.clone(), problem);
if let Some(report) = type_problem(&alloc, module_path.clone(), problem) {
let mut buf = String::new();
report.render_color_terminal(&mut buf, &alloc, &palette);
lines.push(buf);
}
}
for problem in mono_problems {
let report = mono_problem(&alloc, module_path.clone(), problem);

View file

@ -16,28 +16,32 @@ pub fn type_problem<'b>(
alloc: &'b RocDocAllocator<'b>,
filename: PathBuf,
problem: solve::TypeError,
) -> Report<'b> {
) -> Option<Report<'b>> {
use solve::TypeError::*;
fn report(title: String, doc: RocDocBuilder<'_>, filename: PathBuf) -> Report<'_> {
Report {
fn report(title: String, doc: RocDocBuilder<'_>, filename: PathBuf) -> Option<Report<'_>> {
Some(Report {
title,
filename,
doc,
severity: Severity::RuntimeError,
}
})
}
match problem {
BadExpr(region, category, found, expected) => {
to_expr_report(alloc, filename, region, category, found, expected)
}
BadPattern(region, category, found, expected) => {
to_pattern_report(alloc, filename, region, category, found, expected)
}
CircularType(region, symbol, overall_type) => {
to_circular_report(alloc, filename, region, symbol, overall_type)
}
BadExpr(region, category, found, expected) => Some(to_expr_report(
alloc, filename, region, category, found, expected,
)),
BadPattern(region, category, found, expected) => Some(to_pattern_report(
alloc, filename, region, category, found, expected,
)),
CircularType(region, symbol, overall_type) => Some(to_circular_report(
alloc,
filename,
region,
symbol,
overall_type,
)),
UnexposedLookup(symbol) => {
let title = "UNRECOGNIZED NAME".to_string();
let doc = alloc
@ -97,6 +101,8 @@ pub fn type_problem<'b>(
report(title, doc, filename)
}
SolvedTypeError => None,
other => panic!("unhandled bad type: {:?}", other),
}
}

View file

@ -154,9 +154,10 @@ mod test_reporting {
}
for problem in type_problems {
let report = type_problem(&alloc, filename.clone(), problem.clone());
if let Some(report) = type_problem(&alloc, filename.clone(), problem.clone()) {
reports.push(report);
}
}
for problem in mono_problems {
let report = mono_problem(&alloc, filename.clone(), problem.clone());

View file

@ -143,13 +143,14 @@ fn create_llvm_module<'a>(
}
for problem in type_problems {
let report = type_problem(&alloc, module_path.clone(), problem);
if let Some(report) = type_problem(&alloc, module_path.clone(), problem) {
let mut buf = String::new();
report.render_color_terminal(&mut buf, &alloc, &palette);
lines.push(buf);
}
}
for problem in mono_problems {
let report = mono_problem(&alloc, module_path.clone(), problem);