Skip to content

Commit

Permalink
Use one line more often
Browse files Browse the repository at this point in the history
  • Loading branch information
azdavis committed Nov 30, 2023
1 parent f3b3149 commit bdd51ad
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
21 changes: 8 additions & 13 deletions crates/sml-statics-types/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,19 +366,14 @@ impl fmt::Display for RecordMetaVarDisplay<'_> {
impl Incompatible {
/// Returns a value that displays this.
#[must_use]
pub fn display<'a>(
&'a self,
st: &'a St,
lines: config::DiagnosticLines,
) -> impl fmt::Display + 'a {
IncompatibleDisplay { flavor: self, st, lines }
pub fn display<'a>(&'a self, st: &'a St) -> impl fmt::Display + 'a {
IncompatibleDisplay { flavor: self, st }
}
}

struct IncompatibleDisplay<'a> {
flavor: &'a Incompatible,
st: &'a St,
lines: config::DiagnosticLines,
}

impl fmt::Display for IncompatibleDisplay<'_> {
Expand All @@ -400,8 +395,8 @@ impl fmt::Display for IncompatibleDisplay<'_> {
write!(f, "`{a}` and `{b}` are different type constructors")
}
Incompatible::HeadMismatch(a, b) => {
let a_display = a.display(self.st, self.lines);
let b_display = b.display(self.st, self.lines);
let a_display = a.display(self.st, config::DiagnosticLines::One);
let b_display = b.display(self.st, config::DiagnosticLines::One);
let a_desc = a.desc();
let b_desc = b.desc();
write!(f, "`{a_display}` is {a_desc}, but `{b_display}` is {b_desc}")
Expand All @@ -417,21 +412,21 @@ impl fmt::Display for IncompatibleDisplay<'_> {
write!(f, "record types are not compatible with the `{ov}` overload")
}
Incompatible::OverloadHeadMismatch(ov, ty) => {
let ty_display = ty.display(self.st, self.lines);
let ty_display = ty.display(self.st, config::DiagnosticLines::One);
let ty_desc = ty.desc();
write!(f, "`{ov}` is an overloaded type, but `{ty_display}` is {ty_desc}")
}
Incompatible::UnresolvedRecordMissingRow(lab) => {
write!(f, "unresolved record type is missing field: `{lab}`")
}
Incompatible::UnresolvedRecordHeadMismatch(rows, ty) => {
let ty_display = ty.display(self.st, self.lines);
let ty_display = ty.display(self.st, config::DiagnosticLines::One);
let ty_desc = ty.desc();
let rows = record_meta_var(self.st, rows, self.lines);
let rows = record_meta_var(self.st, rows, config::DiagnosticLines::One);
write!(f, "`{rows}` is an unresolved record type, but `{ty_display}` is {ty_desc}")
}
Incompatible::NotEqTy(ty, not_eq) => {
let ty = ty.display(self.st, self.lines);
let ty = ty.display(self.st, config::DiagnosticLines::One);
write!(f, "not an equality type because it contains {not_eq}: `{ty}`")
}
}
Expand Down
22 changes: 11 additions & 11 deletions crates/sml-statics/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ impl fmt::Display for ErrorKindDisplay<'_> {
ErrorKind::Missing(item, name) => write!(f, "missing {item} required by signature: `{name}`"),
ErrorKind::Extra(item, name) => write!(f, "extra {item} not present in signature: `{name}`"),
ErrorKind::Circularity(circ) => {
let mv = circ.meta_var.display(self.st, self.lines);
let ty = circ.ty.display(self.st, self.lines);
let mv = circ.meta_var.display(self.st, config::DiagnosticLines::One);
let ty = circ.ty.display(self.st, config::DiagnosticLines::One);
write!(f, "circular type: `{mv}` occurs in `{ty}`")
}
ErrorKind::IncompatibleTys(reason, want, got) => {
let reason = reason.display(self.st, self.lines);
let reason = reason.display(self.st);
write!(f, "incompatible types: {reason}")?;
let want = want.display(self.st, self.lines);
let got = got.display(self.st, self.lines);
let want = want.display(self.st, config::DiagnosticLines::One);
let got = got.display(self.st, config::DiagnosticLines::One);
match self.lines {
config::DiagnosticLines::One => {
write!(f, ": expected `{want}`, found `{got}`")
Expand All @@ -112,7 +112,7 @@ impl fmt::Display for ErrorKindDisplay<'_> {
ErrorKind::ConPatMustHaveArg => f.write_str("missing argument for constructor pattern"),
ErrorKind::InvalidAsPatName(name) => write!(f, "invalid `as` pat name: `{name}`"),
ErrorKind::TyEscape(ty) => {
let ty = ty.display(self.st, self.lines);
let ty = ty.display(self.st, config::DiagnosticLines::One);
write!(f, "type escapes its scope: `{ty}`")
}
ErrorKind::ValRecExpNotFn => f.write_str("the expression for a `val rec` was not a `fn`"),
Expand All @@ -124,15 +124,15 @@ impl fmt::Display for ErrorKindDisplay<'_> {
ErrorKind::InvalidRebindName(name) => write!(f, "cannot re-bind name: `{name}`"),
ErrorKind::WrongIdStatus(name) => write!(f, "incompatible identifier statuses: `{name}`"),
ErrorKind::UnresolvedRecordTy(rows) => {
let ty = record_meta_var(self.st, rows, self.lines);
let ty = record_meta_var(self.st, rows, config::DiagnosticLines::One);
write!(f, "cannot resolve `...` in record type: `{ty}`")
}
ErrorKind::OrPatNotSameBindings(name) => {
write!(f, "`{name}` was bound in one alternative, but not in another")
}
ErrorKind::DecNotAllowedHere => f.write_str("`signature` or `functor` not allowed here"),
ErrorKind::ExpHole(ty) => {
let ty = ty.display(self.st, self.lines);
let ty = ty.display(self.st, config::DiagnosticLines::One);
write!(f, "expression hole with type `{ty}`")
}
ErrorKind::TyHole => f.write_str("type hole"),
Expand All @@ -146,11 +146,11 @@ impl fmt::Display for ErrorKindDisplay<'_> {
f.write_str("type variable bound at `val` or `fun` not allowed here")
}
ErrorKind::CannotShareTy(path, ts) => {
let ts = ts.display(self.st, self.lines);
let ts = ts.display(self.st, config::DiagnosticLines::One);
write!(f, "cannot share type `{path}` as `{ts}`")
}
ErrorKind::CannotRealizeTy(path, ts) => {
let ts = ts.display(self.st, self.lines);
let ts = ts.display(self.st, config::DiagnosticLines::One);
write!(f, "cannot realize type `{path}` as `{ts}`")
}
ErrorKind::InvalidEq(name) => write!(f, "calling `=` or `<>` on `{name}`"),
Expand All @@ -176,7 +176,7 @@ impl fmt::Display for ErrorKindDisplay<'_> {
write!(f, "`fn {name} => f {name}`, can be simplified to `f`")
}
ErrorKind::ShadowInCaseWithSameTy(name, ty_scheme) => {
let ty_scheme = ty_scheme.display(self.st, self.lines);
let ty_scheme = ty_scheme.display(self.st, config::DiagnosticLines::One);
write!(f, "this pattern, which binds `{name}` with type `{ty_scheme}`, ")?;
write!(f, "does not check any part of the matched expression for equality with the ")?;
write!(f, "existing `{name}`, which has the same type, and which was already in scope")
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ The versioning system is basically the following:
- If there's a really "big" change.
- As mentioned, the "major" version is 0.

## main

- Use multi-line types less often in error messages.

## v0.14.0

- Warn when a `.sig` file doesn't contain 1 `signature`.
Expand Down

0 comments on commit bdd51ad

Please sign in to comment.