FIX: Handle binding and named field collisions in lookups.

This commit is contained in:
Jeremy Wall 2019-01-13 22:45:15 -06:00
parent 207a08d112
commit 5c2d8662bf
3 changed files with 27 additions and 10 deletions

View File

@ -67,4 +67,15 @@ let idx = 1;
assert { assert {
ok = list.(idx) == 2, ok = list.(idx) == 2,
desc = "expected 2, got @" % (list.(idx)), desc = "expected 2, got @" % (list.(idx)),
};
let repeated = {
inner = {
repeated = "foo",
},
};
assert {
ok = repeated.inner.repeated == "foo",
desc = "selectors don't jump the line",
}; };

View File

@ -126,24 +126,30 @@ impl Scope {
if &sym.val == "self" && is_symbol { if &sym.val == "self" && is_symbol {
return self.curr_val.clone(); 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() { 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) { &Val::Tuple(ref fs) => match Self::lookup_in_tuple(&sym.pos, &sym.val, fs) {
Ok(v) => Some(v), Ok(v) => return Some(v),
Err(_) => None, Err(_) => {
// noop
}
}, },
&Val::List(ref fs) => { &Val::List(ref fs) => {
match Self::lookup_in_list(&sym.pos, &Val::Str(sym.val.clone()), fs) { match Self::lookup_in_list(&sym.pos, &Val::Str(sym.val.clone()), fs) {
Ok(v) => Some(v), Ok(v) => return Some(v),
Err(_) => None, Err(_) => {
// noop
}
} }
} }
_ => None, _ => {
// noop
}
}; };
} }
if self.build_output.contains_key(sym) {
return Some(self.build_output[sym].clone());
}
None None
} }

View File

@ -51,7 +51,7 @@ assert asserts.equal{
right="TODO description", right="TODO description",
}; };
let bad_ok_result = t.asserts.ok{ let bad_ok_result = asserts.ok{
test=false, test=false,
}; };
assert asserts.equal{ assert asserts.equal{