From d4675d9138e748c0317ddeb156e6cb5103dbebfe Mon Sep 17 00:00:00 2001 From: Wind Date: Mon, 10 Feb 2025 15:32:05 +0800 Subject: [PATCH] allow `export alias` in repl (#15054) # Description Fixes: #15048 The issue is happened while `parse_export_in_block`, it makes a call to `parse_internal_call`, which may be an error. But in reality, these errors are not useful, all useful errors will be generated by `parse_xxx` at the end of the function. # User-Facing Changes The following code should no longer raise error: ``` export alias a = overlay use ``` # Tests + Formatting Added 1 test. # After Submitting NaN --- crates/nu-command/tests/commands/alias.rs | 6 ++++++ crates/nu-parser/src/parse_keywords.rs | 7 ++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/nu-command/tests/commands/alias.rs b/crates/nu-command/tests/commands/alias.rs index 03df53ae42..9711225f9c 100644 --- a/crates/nu-command/tests/commands/alias.rs +++ b/crates/nu-command/tests/commands/alias.rs @@ -163,3 +163,9 @@ fn alias_default_help() { let first_help_line = actual.out.lines().next().unwrap(); assert!(first_help_line.starts_with("Alias for `echo 'I am a beautiful teapot'`")); } + +#[test] +fn export_alias_with_overlay_use_works() { + let actual = nu!("export alias teapot = overlay use"); + assert!(actual.err.is_empty()) +} diff --git a/crates/nu-parser/src/parse_keywords.rs b/crates/nu-parser/src/parse_keywords.rs index 5eb845523a..057443c141 100644 --- a/crates/nu-parser/src/parse_keywords.rs +++ b/crates/nu-parser/src/parse_keywords.rs @@ -1147,6 +1147,7 @@ pub fn parse_export_in_block( } if let Some(decl_id) = working_set.find_decl(full_name.as_bytes()) { + let starting_error_count = working_set.parse_errors.len(); let ParsedInternalCall { call, output, .. } = parse_internal_call( working_set, if full_name == "export" { @@ -1161,12 +1162,12 @@ pub fn parse_export_in_block( }, decl_id, ); + // don't need errors generated by parse_internal_call + // further error will be generated by detail `parse_xxx` function. + working_set.parse_errors.truncate(starting_error_count); let decl = working_set.get_decl(decl_id); - - let starting_error_count = working_set.parse_errors.len(); check_call(working_set, call_span, &decl.signature(), &call); - let Ok(is_help) = has_flag_const(working_set, &call, "help") else { return garbage_pipeline(working_set, &lite_command.parts); };