From 2599c0ebdca92f1f2ddaff2318912d7d85f2240c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Mon, 2 Jan 2023 11:25:48 +0100 Subject: [PATCH] Interpreter - Don't return interpreter results from the environment's methods --- src/interpreter/environment.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/interpreter/environment.rs b/src/interpreter/environment.rs index 3ea5092..c188cb3 100644 --- a/src/interpreter/environment.rs +++ b/src/interpreter/environment.rs @@ -2,7 +2,7 @@ use std::{cell::RefCell, collections::HashMap, rc::Rc}; use crate::{errors::InterpreterError, tokens::Token}; -use super::{InterpreterResult, Value}; +use super::Value; /// A mutable reference to an environment. pub type EnvironmentRef = Rc>; @@ -40,7 +40,7 @@ impl Environment { } /// Get the value of a variable. - pub fn get(&self, name: &Token) -> InterpreterResult { + pub fn get(&self, name: &Token) -> Result { match self.values.get(&name.lexeme as &str) { None => match &self.enclosing { None => Err(InterpreterError::new( @@ -58,10 +58,10 @@ impl Environment { } /// Assign a value to an existing variable. - pub fn assign(&mut self, name: &Token, value: Value) -> InterpreterResult { + pub fn assign(&mut self, name: &Token, value: Value) -> Result<(), InterpreterError> { if self.values.contains_key(&name.lexeme as &str) { self.values.insert(name.lexeme.clone(), Some(value)); - Ok(Value::Nil) + Ok(()) } else { match &mut self.enclosing { None => Err(InterpreterError::new(