Sort overlap errors by position
@@ -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()),
