From 41de5674daa3d17c7597ace382cfa33c49c919b7 Mon Sep 17 00:00:00 2001 From: Doonv <58695417+doonv@users.noreply.github.com> Date: Sat, 20 Jan 2024 23:38:18 +0200 Subject: [PATCH] Add error message for `RunError::CannotIndexValue` --- src/builtin_parser/runner.rs | 4 ++-- src/builtin_parser/runner/error.rs | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/builtin_parser/runner.rs b/src/builtin_parser/runner.rs index a9c7aca..02905dd 100644 --- a/src/builtin_parser/runner.rs +++ b/src/builtin_parser/runner.rs @@ -191,7 +191,7 @@ fn eval_expression( match reflect.reflect_mut() { ReflectMut::Enum(dyn_enum) => { let TypeInfo::Enum(enum_info) = registeration.type_info() else { - unreachable!(); + unreachable!() }; let Spanned { span, value } = *value_expr; match value { @@ -565,7 +565,7 @@ fn eval_member_expression( Ok(Value::Resource(resource)) } - _ => Err(RunError::CannotIndexValue(left_span)), + _ => Err(RunError::CannotIndexValue(left_span.wrap(left))), } } diff --git a/src/builtin_parser/runner/error.rs b/src/builtin_parser/runner/error.rs index 2895ec9..ba51978 100644 --- a/src/builtin_parser/runner/error.rs +++ b/src/builtin_parser/runner/error.rs @@ -26,7 +26,7 @@ pub enum RunError { }, VariableNotFound(Spanned), ExpectedNumberAfterUnaryOperator(Spanned), - CannotIndexValue(Span), + CannotIndexValue(Spanned), FieldNotFoundInStruct(Span), ReferenceToMovedData(Span), VariableMoved(Spanned), @@ -74,7 +74,7 @@ impl RunError { Custom { span, .. } => vec![span.clone()], VariableNotFound(Spanned { span, .. }) => vec![span.clone()], ExpectedNumberAfterUnaryOperator(Spanned { span, .. }) => vec![span.clone()], - CannotIndexValue(span) => vec![span.clone()], + CannotIndexValue(Spanned { span, .. }) => vec![span.clone()], FieldNotFoundInStruct(span) => vec![span.clone()], CannotDereferenceValue(Spanned { span, .. }) => vec![span.clone()], ReferenceToMovedData(span) => vec![span.clone()], @@ -115,7 +115,9 @@ impl RunError { value.natural_kind() ) .into(), - CannotIndexValue(_) => todo!(), + CannotIndexValue(Spanned { span: _, value }) => { + format!("Cannot index {} with a member expression.", value.kind()).into() + } FieldNotFoundInStruct(_) => todo!(), ReferenceToMovedData(_) => todo!(), VariableMoved(Spanned { value, .. }) => format!("Variable `{value}` was moved.").into(),