From a6e455efc37c3017a5fb694530fa1cce79877ffa Mon Sep 17 00:00:00 2001 From: pwygab <88221256+merelymyself@users.noreply.github.com> Date: Tue, 23 May 2023 00:51:07 +0800 Subject: [PATCH] upserting data of a cellpath that doesn't exist into a record creates the cellpath (#9257) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description Fixes #9254. # User-Facing Changes upserting data of a cellpath that doesn't exist into a record now creates the cellpath. # Tests + Formatting ``` ~/CodingProjects/nushell> mut a = {} ~/CodingProjects/nushell> $a.b.c = 99 ~/CodingProjects/nushell> $a ╭───┬────────────╮ │ │ ╭───┬────╮ │ │ b │ │ c │ 99 │ │ │ │ ╰───┴────╯ │ ╰───┴────────────╯ ``` # After Submitting --- crates/nu-command/tests/commands/mut_.rs | 6 ++++++ crates/nu-protocol/src/value/mod.rs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/nu-command/tests/commands/mut_.rs b/crates/nu-command/tests/commands/mut_.rs index bc274c8917..cb8f12d6ac 100644 --- a/crates/nu-command/tests/commands/mut_.rs +++ b/crates/nu-command/tests/commands/mut_.rs @@ -171,3 +171,9 @@ fn mut_path_operator_assign() { assert_eq!(actual.out, "5"); } + +#[test] +fn mut_records_update_properly() { + let actual = nu!(pipeline("mut a = {}; $a.b.c = 100; $a.b.c")); + assert_eq!(actual.out, "100"); +} diff --git a/crates/nu-protocol/src/value/mod.rs b/crates/nu-protocol/src/value/mod.rs index 24de846e3d..faa303986d 100644 --- a/crates/nu-protocol/src/value/mod.rs +++ b/crates/nu-protocol/src/value/mod.rs @@ -1036,8 +1036,8 @@ impl Value { } } if !found { + cols.push(col_name.clone()); if cell_path.len() == 1 { - cols.push(col_name.clone()); vals.push(new_val); } else { let mut new_col = Value::Record {