Skip to content

Commit 6203c80

Browse files
sunshowersepage
authored andcommitted
fix: Always overwrite with tables, even if empty
While the last commit restored behavior to mostly where it was in v0.15.2, this commit introduces a behavior change with the goal of treating empty tables the same as non-empty ones (in particular, `int_to_empty` is now treated the same as `int_to_non_empty`, both of them overwriting the integer with the table). Treating them the same makes a lot of sense logically, and the fact that we weren't doing so is probably a bug in the old implementation. But it is a notable behavior change, and one worth considering carefully.
1 parent c28334c commit 6203c80

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/path/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ impl Expression {
150150
let parent = self.get_mut_forcibly(root);
151151
match value.kind {
152152
ValueKind::Table(ref incoming_map) => {
153-
// If the parent is nil, treat it as an empty table
154-
if matches!(parent.kind, ValueKind::Nil) {
153+
// If the parent is not a table, overwrite it, treating it as a
154+
// table
155+
if !matches!(parent.kind, ValueKind::Table(_)) {
155156
*parent = Map::<String, Value>::new().into();
156157
}
157158

tests/testsuite/merge.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,17 @@ Settings {
338338
.unwrap();
339339
let res = cfg.try_deserialize::<Settings>();
340340
assert_data_eq!(
341-
res.unwrap_err().to_string(),
342-
str!["invalid type: integer `42`, expected struct Profile for key `profile.int_to_empty`"]
341+
res.unwrap().to_debug(),
342+
str![[r#"
343+
Settings {
344+
profile: {
345+
"int_to_empty": Profile {
346+
name: None,
347+
},
348+
},
349+
}
350+
351+
"#]]
343352
);
344353

345354
// * int_to_non_empty: int -> map with k/v

0 commit comments

Comments
 (0)