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.
This commit is contained in:
@@ -307,7 +307,7 @@ impl TypeChecker {
|
|||||||
(a, b) if a == b => {}
|
(a, b) if a == b => {}
|
||||||
(StaticType::TypeVar(n), ty) | (ty, StaticType::TypeVar(n)) => {
|
(StaticType::TypeVar(n), ty) | (ty, StaticType::TypeVar(n)) => {
|
||||||
if Self::occurs(n, &ty, &subst) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
// Release the borrow before routing through bind_var so that
|
// Release the borrow before routing through bind_var so that
|
||||||
@@ -369,7 +369,7 @@ impl TypeChecker {
|
|||||||
self.unify(*body, other, diag);
|
self.unify(*body, other, diag);
|
||||||
}
|
}
|
||||||
(a, b) => {
|
(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(
|
diag.push_error(
|
||||||
format!(
|
format!(
|
||||||
"Cannot destructure type {} as a tuple/vector",
|
"Cannot destructure type {} as a tuple/vector",
|
||||||
specialized_ty
|
specialized_ty.display_compact()
|
||||||
),
|
),
|
||||||
Some(node.identity.clone()),
|
Some(node.identity.clone()),
|
||||||
);
|
);
|
||||||
@@ -1194,7 +1194,7 @@ impl TypeChecker {
|
|||||||
format!(
|
format!(
|
||||||
"Cannot access field :{} on non-record type {}",
|
"Cannot access field :{} on non-record type {}",
|
||||||
field.name(),
|
field.name(),
|
||||||
rec_typed.ty
|
rec_typed.ty.display_compact()
|
||||||
),
|
),
|
||||||
Some(rec_typed.identity.clone()),
|
Some(rec_typed.identity.clone()),
|
||||||
);
|
);
|
||||||
@@ -1519,7 +1519,7 @@ impl TypeChecker {
|
|||||||
diag.push_error(
|
diag.push_error(
|
||||||
format!(
|
format!(
|
||||||
"Type mismatch in 'again' call: expected {}, but got {}",
|
"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()),
|
Some(node.identity.clone()),
|
||||||
);
|
);
|
||||||
|
|||||||
+1
-1
@@ -498,7 +498,7 @@ impl StaticType {
|
|||||||
/// Abbreviates verbose types like records to keep diagnostics readable.
|
/// Abbreviates verbose types like records to keep diagnostics readable.
|
||||||
pub fn display_compact(&self) -> String {
|
pub fn display_compact(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
StaticType::Record(_) => "record".to_string(),
|
StaticType::Record(_) => "<record>".to_string(),
|
||||||
StaticType::Tuple(elements) => {
|
StaticType::Tuple(elements) => {
|
||||||
let inner: Vec<String> = elements.iter().map(|e| e.display_compact()).collect();
|
let inner: Vec<String> = elements.iter().map(|e| e.display_compact()).collect();
|
||||||
format!("[{}]", inner.join(" "))
|
format!("[{}]", inner.join(" "))
|
||||||
|
|||||||
Reference in New Issue
Block a user