1
0

Improve error

This commit is contained in:
Jeff 2024-07-01 18:02:12 -04:00
parent 92f098b58b
commit 7ec640a3a1
2 changed files with 13 additions and 5 deletions

View File

@ -218,7 +218,9 @@ impl AbstractNode for ValueNode {
r#type,
),
(None, Some(_)) => {
return Err(ValidationError::ExpectedNonValueStatement(body.position))
return Err(ValidationError::ExpectedNonValueStatement(
body.node.last_statement().position(),
))
}
(Some(constructor), None) => {
return Err(ValidationError::ExpectedValueStatement(

View File

@ -345,10 +345,16 @@ impl InterpreterError {
Label::new((self.source_id.clone(), position.0..position.1))
.with_message("Expected a statement that yields a value."),
),
ValidationError::ExpectedNonValueStatement(position) => builder.add_label(
ValidationError::ExpectedNonValueStatement(position) => {
builder.add_label(
Label::new((self.source_id.clone(), position.0..position.1))
.with_message("Expected a statement that does not yield a value."),
),
);
builder.add_label(
Label::new((self.source_id.clone(), position.0..position.1))
.with_message("Try adding a semicolon here."),
);
}
ValidationError::ExpectedFunction { actual, position } => builder.add_label(
Label::new((self.source_id.clone(), position.0..position.1)).with_message(
format!(