mirror of
https://github.com/nushell/nushell.git
synced 2024-11-07 17:14:23 +01:00
Make aliased call not look up predeclarations (#9244)
This commit is contained in:
parent
01a00641f9
commit
429c4332b1
@ -149,3 +149,9 @@ fn alias_multiword_name() {
|
||||
let actual = nu!(r#"alias "foo bar" = echo 'test'; foo bar"#);
|
||||
assert_eq!(actual.out, "test");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alias_ordering() {
|
||||
let actual = nu!(r#"alias bar = echo; def echo [] { 'dummy echo' }; bar 'foo'"#);
|
||||
assert_eq!(actual.out, "foo");
|
||||
}
|
||||
|
@ -171,9 +171,9 @@ fn use_export_env_combined() {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"spam.nu",
|
||||
r#"
|
||||
def foo [] { 'foo' }
|
||||
alias bar = foo
|
||||
export-env { let-env FOO = (bar) }
|
||||
def foo [] { 'foo' }
|
||||
"#,
|
||||
)]);
|
||||
|
||||
|
@ -804,6 +804,8 @@ pub fn parse_alias(
|
||||
}
|
||||
|
||||
let starting_error_count = working_set.parse_errors.len();
|
||||
working_set.search_predecls = false;
|
||||
|
||||
let expr = parse_call(
|
||||
working_set,
|
||||
replacement_spans,
|
||||
@ -811,6 +813,8 @@ pub fn parse_alias(
|
||||
false, // TODO: Should this be set properly???
|
||||
);
|
||||
|
||||
working_set.search_predecls = true;
|
||||
|
||||
if starting_error_count != working_set.parse_errors.len() {
|
||||
if let Some(e) = working_set.parse_errors.get(starting_error_count) {
|
||||
if let ParseError::MissingPositional(..) = e {
|
||||
|
@ -952,6 +952,8 @@ pub struct StateWorkingSet<'a> {
|
||||
pub currently_parsed_cwd: Option<PathBuf>,
|
||||
/// All previously parsed module files. Used to protect against circular imports.
|
||||
pub parsed_module_files: Vec<PathBuf>,
|
||||
/// Whether or not predeclarations are searched when looking up a command (used with aliases)
|
||||
pub search_predecls: bool,
|
||||
pub parse_errors: Vec<ParseError>,
|
||||
}
|
||||
|
||||
@ -1130,6 +1132,7 @@ impl<'a> StateWorkingSet<'a> {
|
||||
type_scope: TypeScope::default(),
|
||||
currently_parsed_cwd: permanent_state.currently_parsed_cwd.clone(),
|
||||
parsed_module_files: vec![],
|
||||
search_predecls: true,
|
||||
parse_errors: vec![],
|
||||
}
|
||||
}
|
||||
@ -1456,9 +1459,11 @@ impl<'a> StateWorkingSet<'a> {
|
||||
let mut visibility: Visibility = Visibility::new();
|
||||
|
||||
for scope_frame in self.delta.scope.iter().rev() {
|
||||
if let Some(decl_id) = scope_frame.predecls.get(name) {
|
||||
if visibility.is_decl_id_visible(decl_id) {
|
||||
return Some(*decl_id);
|
||||
if self.search_predecls {
|
||||
if let Some(decl_id) = scope_frame.predecls.get(name) {
|
||||
if visibility.is_decl_id_visible(decl_id) {
|
||||
return Some(*decl_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1466,9 +1471,11 @@ impl<'a> StateWorkingSet<'a> {
|
||||
for overlay_frame in scope_frame.active_overlays(&mut removed_overlays).rev() {
|
||||
visibility.append(&overlay_frame.visibility);
|
||||
|
||||
if let Some(decl_id) = overlay_frame.predecls.get(name) {
|
||||
if visibility.is_decl_id_visible(decl_id) {
|
||||
return Some(*decl_id);
|
||||
if self.search_predecls {
|
||||
if let Some(decl_id) = overlay_frame.predecls.get(name) {
|
||||
if visibility.is_decl_id_visible(decl_id) {
|
||||
return Some(*decl_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user