From 5c2d8662bf443ed69bdd98dd47e02b794e9cedf8 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Sun, 13 Jan 2019 22:45:15 -0600 Subject: [PATCH] FIX: Handle binding and named field collisions in lookups. --- integration_tests/selectors_test.ucg | 11 +++++++++++ src/build/scope.rs | 24 +++++++++++++++--------- std/tests/testing_test.ucg | 2 +- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/integration_tests/selectors_test.ucg b/integration_tests/selectors_test.ucg index efaea24..8341c62 100644 --- a/integration_tests/selectors_test.ucg +++ b/integration_tests/selectors_test.ucg @@ -67,4 +67,15 @@ let idx = 1; assert { ok = list.(idx) == 2, desc = "expected 2, got @" % (list.(idx)), +}; + +let repeated = { + inner = { + repeated = "foo", + }, +}; + +assert { + ok = repeated.inner.repeated == "foo", + desc = "selectors don't jump the line", }; \ No newline at end of file diff --git a/src/build/scope.rs b/src/build/scope.rs index be0ba6f..6e124f6 100644 --- a/src/build/scope.rs +++ b/src/build/scope.rs @@ -126,24 +126,30 @@ impl Scope { if &sym.val == "self" && is_symbol { return self.curr_val.clone(); } - if self.build_output.contains_key(sym) { - return Some(self.build_output[sym].clone()); - } if self.search_curr_val && self.curr_val.is_some() { - return match self.curr_val.as_ref().unwrap().as_ref() { + match self.curr_val.as_ref().unwrap().as_ref() { &Val::Tuple(ref fs) => match Self::lookup_in_tuple(&sym.pos, &sym.val, fs) { - Ok(v) => Some(v), - Err(_) => None, + Ok(v) => return Some(v), + Err(_) => { + // noop + } }, &Val::List(ref fs) => { match Self::lookup_in_list(&sym.pos, &Val::Str(sym.val.clone()), fs) { - Ok(v) => Some(v), - Err(_) => None, + Ok(v) => return Some(v), + Err(_) => { + // noop + } } } - _ => None, + _ => { + // noop + } }; } + if self.build_output.contains_key(sym) { + return Some(self.build_output[sym].clone()); + } None } diff --git a/std/tests/testing_test.ucg b/std/tests/testing_test.ucg index fd02fd1..1a6c79a 100644 --- a/std/tests/testing_test.ucg +++ b/std/tests/testing_test.ucg @@ -51,7 +51,7 @@ assert asserts.equal{ right="TODO description", }; -let bad_ok_result = t.asserts.ok{ +let bad_ok_result = asserts.ok{ test=false, }; assert asserts.equal{