From 7ec640a3a14fc6355b787ff0954bb13732867d50 Mon Sep 17 00:00:00 2001 From: Jeff Date: Mon, 1 Jul 2024 18:02:12 -0400 Subject: [PATCH] Improve error --- dust-lang/src/abstract_tree/value_node.rs | 4 +++- dust-lang/src/lib.rs | 14 ++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/dust-lang/src/abstract_tree/value_node.rs b/dust-lang/src/abstract_tree/value_node.rs index 20301bc..94f8034 100644 --- a/dust-lang/src/abstract_tree/value_node.rs +++ b/dust-lang/src/abstract_tree/value_node.rs @@ -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( diff --git a/dust-lang/src/lib.rs b/dust-lang/src/lib.rs index 364c569..23afc87 100644 --- a/dust-lang/src/lib.rs +++ b/dust-lang/src/lib.rs @@ -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( - Label::new((self.source_id.clone(), position.0..position.1)) - .with_message("Expected a statement that does not yield a value."), - ), + 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!(