From e763a8dcef25a653bb4ede6a8965bd1f10bc54d5 Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Tue, 15 Feb 2022 17:36:24 -0500 Subject: [PATCH] Auto-hide aliases to prevent recursion (#4487) --- crates/nu-parser/src/parser.rs | 3 +++ src/tests/test_parser.rs | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index eacc980905..07c493cc7b 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -851,7 +851,10 @@ pub fn parse_call( new_spans.extend(&spans[(pos + 1)..]); } + working_set.enter_scope(); + working_set.hide_alias(&name); let (mut result, err) = parse_expression(working_set, &new_spans, false); + working_set.exit_scope(); result.replace_span(working_set, expansion_span, orig_span); diff --git a/src/tests/test_parser.rs b/src/tests/test_parser.rs index 75b8b7ddef..dac9593a9f 100644 --- a/src/tests/test_parser.rs +++ b/src/tests/test_parser.rs @@ -33,6 +33,11 @@ fn alias_2_multi_word() -> TestResult { ) } +#[test] +fn alias_recursion() -> TestResult { + run_test_contains(r#"alias ls = (ls | sort-by type name -i); ls"#, " ") +} + #[test] fn block_param1() -> TestResult { run_test("[3] | each { $it + 10 } | get 0", "13")