Skip to content

Commit

Permalink
Merge pull request #218 from HigherOrderCO/bug/sc-485/error-printing-…
Browse files Browse the repository at this point in the history
…not-correctly-breaking-lines

[sc-485] Error printing not correctly breaking lines
  • Loading branch information
imaqtkatt authored Mar 1, 2024
2 parents 2e9b3d3 + a7d91b6 commit 3d7c4e8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}':")?;
Expand Down
6 changes: 4 additions & 2 deletions src/term/check/shared_names.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::{collections::HashMap, fmt::Display};
use std::fmt::Display;

use indexmap::IndexMap;

use crate::term::{Ctx, Name};

Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/term/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/term/transform/resolve_refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
9 changes: 9 additions & 0 deletions tests/golden_tests/compile_file/error_messages.hvm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
data A = (A)
data B = (B)

Foo (C) = *
Foo (D) = *

Foo2 (E) = *

Main = *
11 changes: 11 additions & 0 deletions tests/snapshots/compile_file__error_messages.hvm.snap
Original file line number Diff line number Diff line change
@@ -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'.

0 comments on commit 3d7c4e8

Please sign in to comment.