Merge pull request #218 from HigherOrderCO/bug/sc-485/error-printing-not-correctly-breaking-lines

[sc-485] Error printing not correctly breaking lines
This commit is contained in:
imaqtkatt 2024-03-01 17:41:30 -03:00 committed by GitHub
commit 3d7c4e88fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 27 additions and 6 deletions

View File

@ -69,7 +69,7 @@ impl Info {
pub fn display(&self, verbose: bool) -> impl Display + '_ {
DisplayFn(move |f| {
write!(f, "{}", self.errs.iter().map(|err| err.display(verbose)).join("\n"))?;
writeln!(f, "{}", self.errs.iter().map(|err| err.display(verbose)).join("\n"))?;
for (def_name, errs) in &self.errs_with_def {
writeln!(f, "In definition '{def_name}':")?;

View File

@ -1,4 +1,6 @@
use std::{collections::HashMap, fmt::Display};
use std::fmt::Display;
use indexmap::IndexMap;
use crate::term::{Ctx, Name};
@ -14,7 +16,7 @@ impl Display for TopLevelErr {
impl Ctx<'_> {
/// Checks if exists shared names from definitions, adts and constructors.
pub fn check_shared_names(&mut self) {
let mut checked = HashMap::<&Name, usize>::new();
let mut checked = IndexMap::<&Name, usize>::new();
for adt_name in self.book.adts.keys() {
*checked.entry(adt_name).or_default() += 1;

View File

@ -154,10 +154,10 @@ impl Clone for Term {
Self::Dup { tag: tag.clone(), fst: fst.clone(), snd: snd.clone(), val: val.clone(), nxt: nxt.clone() }
}
Self::Sup { tag, fst, snd } => Self::Sup { tag: tag.clone(), fst: fst.clone(), snd: snd.clone() },
Self::Num { val } => Self::Num { val: val.clone() },
Self::Num { val } => Self::Num { val: *val },
Self::Str { val } => Self::Str { val: val.clone() },
Self::Lst { els } => Self::Lst { els: els.clone() },
Self::Opx { op, fst, snd } => Self::Opx { op: op.clone(), fst: fst.clone(), snd: snd.clone() },
Self::Opx { op, fst, snd } => Self::Opx { op: *op, fst: fst.clone(), snd: snd.clone() },
Self::Mat { args, rules } => Self::Mat { args: args.clone(), rules: rules.clone() },
Self::Ref { nam } => Self::Ref { nam: nam.clone() },
Self::Era => Self::Era,

View File

@ -124,7 +124,6 @@ impl Term {
}
Term::Lst { .. } => unreachable!("Should have been desugared already"),
Term::Lnk { .. } | Term::Ref { .. } | Term::Num { .. } | Term::Str { .. } | Term::Era | Term::Err => {
()
}
}
Ok(())

View File

@ -0,0 +1,9 @@
data A = (A)
data B = (B)
Foo (C) = *
Foo (D) = *
Foo2 (E) = *
Main = *

View File

@ -0,0 +1,11 @@
---
source: tests/golden_tests.rs
input_file: tests/golden_tests/compile_file/error_messages.hvm
---
Duplicated top-level name 'A'.
Duplicated top-level name 'B'.
In definition 'Foo':
Unbound constructor 'C'.
Unbound constructor 'D'.
In definition 'Foo2':
Unbound constructor 'E'.