Sort overlap errors by position (#4975)

This commit is contained in:
Trevor Elliott
2022-09-28 13:23:31 -07:00
committed by GitHub
parent faf31f6216
commit 2e954668c7

View File

@@ -5,12 +5,17 @@ use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet};
use crate::error::{Error, Result, Source, Span};
use crate::lexer::Pos;
use crate::sema::{self, Rule, RuleId, Sym, TermEnv, TermId, TermKind, TypeEnv, VarId};
/// Check for overlap.
pub fn check(tyenv: &TypeEnv, termenv: &TermEnv) -> Result<()> {
let mut errors = check_overlaps(termenv).report(tyenv, termenv);
if cfg!(feature = "overlap-errors") {
errors.sort_by_key(|err| match err {
Error::OverlapError { rules, .. } => rules.first().unwrap().1.from,
_ => Pos::default(),
});
match errors.len() {
0 => Ok(()),
1 => Err(errors.pop().unwrap()),