From a21ad7064c83d04a77c564788884b4e010a27a43 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sat, 18 Sep 2021 02:47:39 -0400 Subject: [PATCH] Ignore type errors that have already been reported --- cli/src/repl/gen.rs | 9 +++--- compiler/build/src/program.rs | 21 +++++++------- compiler/gen_dev/tests/helpers/eval.rs | 9 +++--- compiler/reporting/src/error/type.rs | 32 +++++++++++++--------- compiler/reporting/tests/test_reporting.rs | 5 ++-- compiler/test_gen/src/helpers/eval.rs | 9 +++--- 6 files changed, 48 insertions(+), 37 deletions(-) diff --git a/cli/src/repl/gen.rs b/cli/src/repl/gen.rs index f8cb2acab6..200941919d 100644 --- a/cli/src/repl/gen.rs +++ b/cli/src/repl/gen.rs @@ -107,12 +107,13 @@ pub fn gen_and_eval<'a>( } for problem in type_problems { - let report = type_problem(&alloc, module_path.clone(), problem); - let mut buf = String::new(); + if let Some(report) = type_problem(&alloc, module_path.clone(), problem) { + let mut buf = String::new(); - report.render_color_terminal(&mut buf, &alloc, &palette); + report.render_color_terminal(&mut buf, &alloc, &palette); - lines.push(buf); + lines.push(buf); + } } for problem in mono_problems { diff --git a/compiler/build/src/program.rs b/compiler/build/src/program.rs index 54cba2b385..226bfaf8be 100644 --- a/compiler/build/src/program.rs +++ b/compiler/build/src/program.rs @@ -74,18 +74,19 @@ 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); - let severity = report.severity; - let mut buf = String::new(); + if let Some(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); + report.render_color_terminal(&mut buf, &alloc, &palette); - match severity { - Warning => { - warnings.push(buf); - } - RuntimeError => { - errors.push(buf); + match severity { + Warning => { + warnings.push(buf); + } + RuntimeError => { + errors.push(buf); + } } } } diff --git a/compiler/gen_dev/tests/helpers/eval.rs b/compiler/gen_dev/tests/helpers/eval.rs index 083fbfb0e5..84e5dfdf22 100644 --- a/compiler/gen_dev/tests/helpers/eval.rs +++ b/compiler/gen_dev/tests/helpers/eval.rs @@ -145,12 +145,13 @@ pub fn helper<'a>( } for problem in type_problems { - let report = type_problem(&alloc, module_path.clone(), problem); - let mut buf = String::new(); + if let Some(report) = type_problem(&alloc, module_path.clone(), problem) { + let mut buf = String::new(); - report.render_color_terminal(&mut buf, &alloc, &palette); + report.render_color_terminal(&mut buf, &alloc, &palette); - lines.push(buf); + lines.push(buf); + } } for problem in mono_problems { diff --git a/compiler/reporting/src/error/type.rs b/compiler/reporting/src/error/type.rs index 115d3f6671..18bb619205 100644 --- a/compiler/reporting/src/error/type.rs +++ b/compiler/reporting/src/error/type.rs @@ -16,28 +16,32 @@ pub fn type_problem<'b>( alloc: &'b RocDocAllocator<'b>, filename: PathBuf, problem: solve::TypeError, -) -> Report<'b> { +) -> Option> { use solve::TypeError::*; - fn report(title: String, doc: RocDocBuilder<'_>, filename: PathBuf) -> Report<'_> { - Report { + fn report(title: String, doc: RocDocBuilder<'_>, filename: PathBuf) -> Option> { + 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), } } diff --git a/compiler/reporting/tests/test_reporting.rs b/compiler/reporting/tests/test_reporting.rs index 7575aca5b0..90c71d8112 100644 --- a/compiler/reporting/tests/test_reporting.rs +++ b/compiler/reporting/tests/test_reporting.rs @@ -154,8 +154,9 @@ mod test_reporting { } for problem in type_problems { - let report = type_problem(&alloc, filename.clone(), problem.clone()); - reports.push(report); + if let Some(report) = type_problem(&alloc, filename.clone(), problem.clone()) { + reports.push(report); + } } for problem in mono_problems { diff --git a/compiler/test_gen/src/helpers/eval.rs b/compiler/test_gen/src/helpers/eval.rs index dc4c377c84..be01cdc7ab 100644 --- a/compiler/test_gen/src/helpers/eval.rs +++ b/compiler/test_gen/src/helpers/eval.rs @@ -143,12 +143,13 @@ fn create_llvm_module<'a>( } for problem in type_problems { - let report = type_problem(&alloc, module_path.clone(), problem); - let mut buf = String::new(); + if let Some(report) = type_problem(&alloc, module_path.clone(), problem) { + let mut buf = String::new(); - report.render_color_terminal(&mut buf, &alloc, &palette); + report.render_color_terminal(&mut buf, &alloc, &palette); - lines.push(buf); + lines.push(buf); + } } for problem in mono_problems {