diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-05-01 22:49:54 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-05-01 22:49:54 +0200 |
commit | 9fd4f08d1018e3c255289a1978778fb3de8de3f4 (patch) | |
tree | ff630f6003b03039ee15f74b541a5dd3cd497bc4 /crates | |
parent | a9897e284f56f383ade2c7fcb50317d7ba3c7dda (diff) | |
download | rebel-main.tar rebel-main.zip |
rebel-lang: scope: minor code cleanupmain
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rebel-lang/src/scope.rs | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/crates/rebel-lang/src/scope.rs b/crates/rebel-lang/src/scope.rs index 08149a9..3c72a11 100644 --- a/crates/rebel-lang/src/scope.rs +++ b/crates/rebel-lang/src/scope.rs @@ -220,23 +220,15 @@ impl Context { (Type::Tuple(type_elems), Value::Tuple(value_elems)) => { let index: usize = field.name.parse().or(Err(Error::typ("no such field")))?; - ( - type_elems - .get_mut(index) - .ok_or(Error::typ("no such field"))?, - value_elems - .get_mut(index) - .ok_or(Error::typ("no such field"))?, - ) + type_elems + .get_mut(index) + .zip(value_elems.get_mut(index)) + .ok_or(Error::typ("no such field"))? } - (Type::Struct(type_entries), Value::Struct(value_entries)) => ( - type_entries - .get_mut(field.name) - .ok_or(Error::typ("no such field"))?, - value_entries - .get_mut(field.name) - .ok_or(Error::typ("no such field"))?, - ), + (Type::Struct(type_entries), Value::Struct(value_entries)) => type_entries + .get_mut(field.name) + .zip(value_entries.get_mut(field.name)) + .ok_or(Error::typ("no such field"))?, _ => return Err(Error::typ("invalid field access base type")), }; (inner_type, inner_value, initialized) |