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, r#type,
), ),
(None, Some(_)) => { (None, Some(_)) => {
return Err(ValidationError::ExpectedNonValueStatement(body.position)) return Err(ValidationError::ExpectedNonValueStatement(
body.node.last_statement().position(),
))
} }
(Some(constructor), None) => { (Some(constructor), None) => {
return Err(ValidationError::ExpectedValueStatement( return Err(ValidationError::ExpectedValueStatement(

View File

@ -345,10 +345,16 @@ impl InterpreterError {
Label::new((self.source_id.clone(), position.0..position.1)) Label::new((self.source_id.clone(), position.0..position.1))
.with_message("Expected a statement that yields a value."), .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)) Label::new((self.source_id.clone(), position.0..position.1))
.with_message("Expected a statement that does not yield a value."), .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( ValidationError::ExpectedFunction { actual, position } => builder.add_label(
Label::new((self.source_id.clone(), position.0..position.1)).with_message( Label::new((self.source_id.clone(), position.0..position.1)).with_message(
format!( format!(