1
0

Tweak compiler error messages

This commit is contained in:
Jeff 2025-02-11 07:04:12 -05:00
parent 00f35bd3ae
commit 3599643fad

View File

@ -181,7 +181,7 @@ impl AnnotatedError for CompileError {
fn description(&self) -> &'static str { fn description(&self) -> &'static str {
match self { match self {
Self::CannotAddArguments { .. } => "Cannot add these types", Self::CannotAddArguments { .. } => "Cannot add these types",
Self::CannotAddType { .. } => "Cannot add to this type", Self::CannotAddType { .. } => "Cannot add this type",
Self::ComparisonChain { .. } => "Cannot chain comparison operations", Self::ComparisonChain { .. } => "Cannot chain comparison operations",
Self::CannotDivideArguments { .. } => "Cannot divide these types", Self::CannotDivideArguments { .. } => "Cannot divide these types",
Self::CannotDivideType { .. } => "Cannot divide this type", Self::CannotDivideType { .. } => "Cannot divide this type",
@ -222,6 +222,12 @@ impl AnnotatedError for CompileError {
fn detail_snippets(&self) -> Vec<(String, Span)> { fn detail_snippets(&self) -> Vec<(String, Span)> {
match self { match self {
Self::CannotAddType {
argument_type,
position,
} => {
vec![(format!("Cannot add type `{}`", argument_type), *position)]
}
Self::CannotAddArguments { Self::CannotAddArguments {
left_type, left_type,
left_position, left_position,
@ -229,12 +235,9 @@ impl AnnotatedError for CompileError {
right_position, right_position,
} => { } => {
vec![ vec![
(format!("`{left_type}` value was used here"), *left_position),
( (
format!("A value of type \"{left_type}\" was used here."), format!("`{right_type}` value was used here"),
*left_position,
),
(
format!("A value of type \"{right_type}\" was used here."),
*right_position, *right_position,
), ),
] ]
@ -242,7 +245,7 @@ impl AnnotatedError for CompileError {
Self::ReturnTypeConflict { conflict, position } => { Self::ReturnTypeConflict { conflict, position } => {
vec![( vec![(
format!( format!(
"Expected type {} but found type {}", "Expected type `{}` but found type `{}`",
conflict.expected, conflict.actual conflict.expected, conflict.actual
), ),
*position, *position,
@ -262,7 +265,7 @@ impl AnnotatedError for CompileError {
} => { } => {
vec![( vec![(
format!( format!(
"Type \"{left_type}\" cannot be, added to type \"{right_type}\". Try converting one of the values to the other type." "Type `{left_type}` cannot be added to type `{right_type}`. Try converting one of the values to the other type."
), ),
Span(left_position.0, right_position.1), Span(left_position.0, right_position.1),
)] )]