Make errors nice
This commit is contained in:
parent
c47d09fd1d
commit
2dbbc7b128
@ -122,34 +122,14 @@ impl AbstractNode for ValueNode {
|
||||
return Err(ValidationError::WrongTypeArgumentsCount {
|
||||
expected: parameters.len(),
|
||||
actual: arguments.len(),
|
||||
position: arguments.last().unwrap().position(),
|
||||
});
|
||||
}
|
||||
|
||||
let mut arguments = arguments.iter();
|
||||
let mut found = false;
|
||||
|
||||
for (identifier, content) in variants {
|
||||
if identifier == variant.node {
|
||||
found = true;
|
||||
}
|
||||
|
||||
if let Some(content) = content {
|
||||
for expected_type in &content {
|
||||
if let Type::Generic {
|
||||
concrete_type: None,
|
||||
..
|
||||
} = expected_type
|
||||
{
|
||||
arguments.next().ok_or_else(|| {
|
||||
ValidationError::WrongTypeArgumentsCount {
|
||||
expected: content.len(),
|
||||
actual: arguments.len(),
|
||||
}
|
||||
})?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let found = variants
|
||||
.into_iter()
|
||||
.find(|(identifier, _)| identifier == &variant.node)
|
||||
.is_some();
|
||||
|
||||
if !found {
|
||||
return Err(ValidationError::EnumVariantNotFound {
|
||||
|
@ -184,6 +184,7 @@ pub enum ValidationError {
|
||||
WrongTypeArgumentsCount {
|
||||
expected: usize,
|
||||
actual: usize,
|
||||
position: SourcePosition,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -445,7 +445,19 @@ impl InterpreterError {
|
||||
.add_label(Label::new((self.source_id.clone(), 0..0)).with_message(reason)),
|
||||
ValidationError::CannotUsePath(_) => todo!(),
|
||||
ValidationError::Uninitialized => todo!(),
|
||||
ValidationError::WrongTypeArgumentsCount { expected, actual } => todo!(),
|
||||
ValidationError::WrongTypeArgumentsCount {
|
||||
expected,
|
||||
actual,
|
||||
position,
|
||||
} => builder.add_label(
|
||||
Label::new((self.source_id.clone(), position.0..position.1)).with_message(
|
||||
format!(
|
||||
"Expected {} type arguments but got {}.",
|
||||
expected.fg(type_color),
|
||||
actual.fg(type_color)
|
||||
),
|
||||
),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user