From c403c80f5b11243f1f18c68b3e04b2f95c5743d7 Mon Sep 17 00:00:00 2001 From: Brummel Date: Mon, 30 Mar 2026 11:45:31 +0200 Subject: [PATCH] Refine type error reporting for readability The `display_compact` method on `StaticType` has been enhanced to provide more concise representations of types within error messages. This change aims to improve the clarity of type-related diagnostics generated by the compiler. --- src/ast/compiler/type_checker.rs | 10 +++++----- src/ast/types.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ast/compiler/type_checker.rs b/src/ast/compiler/type_checker.rs index f04f8ed..21342c6 100644 --- a/src/ast/compiler/type_checker.rs +++ b/src/ast/compiler/type_checker.rs @@ -307,7 +307,7 @@ impl TypeChecker { (a, b) if a == b => {} (StaticType::TypeVar(n), ty) | (ty, StaticType::TypeVar(n)) => { if Self::occurs(n, &ty, &subst) { - diag.push_error(format!("Infinite type: ?{} = {}", n, ty), None); + diag.push_error(format!("Infinite type: ?{} = {}", n, ty.display_compact()), None); return; } // Release the borrow before routing through bind_var so that @@ -369,7 +369,7 @@ impl TypeChecker { self.unify(*body, other, diag); } (a, b) => { - diag.push_error(format!("Type mismatch: expected {}, got {}", a, b), None); + diag.push_error(format!("Type mismatch: expected {}, got {}", a.display_compact(), b.display_compact()), None); } } } @@ -1000,7 +1000,7 @@ impl TypeChecker { diag.push_error( format!( "Cannot destructure type {} as a tuple/vector", - specialized_ty + specialized_ty.display_compact() ), Some(node.identity.clone()), ); @@ -1194,7 +1194,7 @@ impl TypeChecker { format!( "Cannot access field :{} on non-record type {}", field.name(), - rec_typed.ty + rec_typed.ty.display_compact() ), Some(rec_typed.identity.clone()), ); @@ -1519,7 +1519,7 @@ impl TypeChecker { diag.push_error( format!( "Type mismatch in 'again' call: expected {}, but got {}", - expected_ty, args_typed.ty + expected_ty.display_compact(), args_typed.ty.display_compact() ), Some(node.identity.clone()), ); diff --git a/src/ast/types.rs b/src/ast/types.rs index 5d4c303..1ae4307 100644 --- a/src/ast/types.rs +++ b/src/ast/types.rs @@ -498,7 +498,7 @@ impl StaticType { /// Abbreviates verbose types like records to keep diagnostics readable. pub fn display_compact(&self) -> String { match self { - StaticType::Record(_) => "record".to_string(), + StaticType::Record(_) => "".to_string(), StaticType::Tuple(elements) => { let inner: Vec = elements.iter().map(|e| e.display_compact()).collect(); format!("[{}]", inner.join(" "))