diff --git a/integration_tests/tuple_test.ucg b/integration_tests/tuple_test.ucg index 48f2c23..953e9a1 100644 --- a/integration_tests/tuple_test.ucg +++ b/integration_tests/tuple_test.ucg @@ -85,4 +85,36 @@ let copy_maybe = base_maybe{ assert | copy_maybe.real == NULL; -|; \ No newline at end of file +|; + +let quotedself_tpl = { + "self" = "myself", +}; + +assert | + quotedself_tpl."self" == "myself"; +|; + +let quotedenv_tpl = { + "env" = "myenv", +}; + +assert | + quotedenv_tpl."env" == "myenv"; +|; + +let unquotedenv_tpl = { + env = "myenv", +}; + +assert | + unquotedenv_tpl."env" == "myenv"; +|; + +let unquotedself_tpl = { + self = "myself", +}; + +assert | + unquotedself_tpl."self" == "myself"; +|; diff --git a/src/build/mod.rs b/src/build/mod.rs index 229410c..f02b3af 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -235,7 +235,7 @@ impl<'a> FileBuilder<'a> { &Value::Str(ref s) => Ok(Rc::new(Val::Str(s.val.to_string()))), &Value::Symbol(ref s) => { scope - .lookup_sym(&(s.into())) + .lookup_sym(&(s.into()), true) .ok_or(Box::new(error::BuildError::new( format!("Unable to find binding {}", s.val,), error::ErrorType::NoSuchSymbol, @@ -253,7 +253,7 @@ impl<'a> FileBuilder<'a> { pos: Position::new(0, 0, 0), val: name.to_string(), }; - self.scope.lookup_sym(&key) + self.scope.lookup_sym(&key, true) } /// Puts the builder in validation mode. @@ -741,14 +741,27 @@ impl<'a> FileBuilder<'a> { right: &Expression, scope: &Scope, ) -> Result, Box> { + let pos = right.pos().clone(); match right { Expression::Copy(_) => return self.eval_expr(right, scope), Expression::Call(_) => return self.eval_expr(right, scope), Expression::Simple(Value::Symbol(ref s)) => { - self.eval_value(&Value::Symbol(s.clone()), scope) + scope + .lookup_sym(s, true) + .ok_or(Box::new(error::BuildError::new( + format!("Unable to find binding {}", s.val,), + error::ErrorType::NoSuchSymbol, + pos, + ))) } Expression::Simple(Value::Str(ref s)) => { - self.eval_value(&Value::Symbol(s.clone()), scope) + scope + .lookup_sym(s, false) + .ok_or(Box::new(error::BuildError::new( + format!("Unable to find binding {}", s.val,), + error::ErrorType::NoSuchSymbol, + pos, + ))) } Expression::Simple(Value::Int(ref i)) => { scope.lookup_idx(right.pos(), &Val::Int(i.val)) diff --git a/src/build/scope.rs b/src/build/scope.rs index a407f08..be0ba6f 100644 --- a/src/build/scope.rs +++ b/src/build/scope.rs @@ -119,11 +119,11 @@ impl Scope { /// valid when the current value is a tuple. /// * everything else is looked up in the currently accumulated build output /// for this execution context. - pub fn lookup_sym(&self, sym: &PositionedItem) -> Option> { - if &sym.val == "env" { + pub fn lookup_sym(&self, sym: &PositionedItem, is_symbol: bool) -> Option> { + if &sym.val == "env" && is_symbol { return Some(self.env.clone()); } - if &sym.val == "self" { + if &sym.val == "self" && is_symbol { return self.curr_val.clone(); } if self.build_output.contains_key(sym) {