fix: attrset update

This commit is contained in:
2025-05-03 14:23:24 +08:00
parent 5e35da49ef
commit 43cfb9be62
2 changed files with 3 additions and 8 deletions

View File

@@ -144,7 +144,7 @@ fn test_attrs() {
test_expr("{ a.b = 1; } ? a.b", boolean!(true)); test_expr("{ a.b = 1; } ? a.b", boolean!(true));
test_expr( test_expr(
"{ a.b = 1; } // { a.c = 2 }", "{ a.b = 1; } // { a.c = 2 }",
attrs! { symbol!("a") => attrs!{ symbol!("b") => int!(1), symbol!("c") => int!(2) } }, attrs! { symbol!("a") => attrs!{ symbol!("c") => int!(2) } },
); );
} }
@@ -164,6 +164,6 @@ fn test_let() {
test_expr(r#"let a = { a = 1; }; b = "a"; in a.${b}"#, int!(1)); test_expr(r#"let a = { a = 1; }; b = "a"; in a.${b}"#, int!(1));
test_expr( test_expr(
r#"let b = "c"; in { a.b = 1; } // { a."a${b}" = 2 }"}"#, r#"let b = "c"; in { a.b = 1; } // { a."a${b}" = 2 }"}"#,
attrs! { symbol!("a") => attrs!{ symbol!("b") => int!(1), symbol!("ac") => int!(2) } }, attrs! { symbol!("a") => attrs!{ symbol!("ac") => int!(2) } },
); );
} }

View File

@@ -26,12 +26,7 @@ impl AttrSet {
pub fn update(mut self, other: AttrSet) -> AttrSet { pub fn update(mut self, other: AttrSet) -> AttrSet {
for (k, v) in other.data.iter() { for (k, v) in other.data.iter() {
if let Some(attr) = self.data.get(k) { self.push_attr(k.clone(), v.clone())
let new_attr = attr.clone().update(v.clone());
self.data.insert_mut(k.clone(), new_attr);
} else {
self.push_attr(k.clone(), v.clone())
}
} }
self self
} }