From 8a9cc33aacf978d95617f79252025a7204d0109d Mon Sep 17 00:00:00 2001 From: Hristo Filaretov Date: Fri, 25 Mar 2022 23:56:40 +0100 Subject: [PATCH] Fix alias import (#4968) * Fix alias import Alias importing was registering the alias id as a decl instead of alias. This caused issues when hiding and then reimporting the alias. * Clippy format Co-authored-by: Hristo Filaretov --- CONTRIBUTING.md | 2 +- crates/nu-protocol/src/engine/engine_state.rs | 2 +- src/tests/test_hiding.rs | 64 +++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b986f1825..97a665d8f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -71,5 +71,5 @@ cargo build - To view verbose logs when developing, enable the `trace` log level. ```shell - cargo build --release --features=extra && cargo run --release --features=extra -- --loglevel trace + cargo build --release --features=extra && cargo run --release --features=extra -- --log-level trace ``` diff --git a/crates/nu-protocol/src/engine/engine_state.rs b/crates/nu-protocol/src/engine/engine_state.rs index 0ed443f6d..3ac5315a3 100644 --- a/crates/nu-protocol/src/engine/engine_state.rs +++ b/crates/nu-protocol/src/engine/engine_state.rs @@ -779,7 +779,7 @@ impl<'a> StateWorkingSet<'a> { for (name, alias_id) in aliases { scope_frame.aliases.insert(name, alias_id); - scope_frame.visibility.use_decl_id(&alias_id); + scope_frame.visibility.use_alias_id(&alias_id); } } diff --git a/src/tests/test_hiding.rs b/src/tests/test_hiding.rs index 7c5a0870d..95f8f3d97 100644 --- a/src/tests/test_hiding.rs +++ b/src/tests/test_hiding.rs @@ -296,6 +296,70 @@ fn hides_def_import_6() -> TestResult { ) } +#[test] +fn hides_def_import_then_reimports() -> TestResult { + run_test( + r#"module spam { export def foo [] { "foo" } }; use spam foo; hide foo; use spam foo; foo"#, + "foo", + ) +} + +#[test] +fn hides_alias_import_1() -> TestResult { + fail_test( + r#"module spam { export alias foo = "foo" }; use spam; hide spam foo; spam foo"#, + "", // we just care if it errors + ) +} + +#[test] +fn hides_alias_import_2() -> TestResult { + fail_test( + r#"module spam { export alias foo = "foo" }; use spam; hide spam; spam foo"#, + "", // we just care if it errors + ) +} + +#[test] +fn hides_alias_import_3() -> TestResult { + fail_test( + r#"module spam { export alias foo = "foo" }; use spam; hide spam [foo]; spam foo"#, + "", // we just care if it errors + ) +} + +#[test] +fn hides_alias_import_4() -> TestResult { + fail_test( + r#"module spam { export alias foo = "foo" }; use spam foo; hide foo; foo"#, + "", // we just care if it errors + ) +} + +#[test] +fn hides_alias_import_5() -> TestResult { + fail_test( + r#"module spam { export alias foo = "foo" }; use spam *; hide foo; foo"#, + "", // we just care if it errors + ) +} + +#[test] +fn hides_alias_import_6() -> TestResult { + fail_test( + r#"module spam { export alias foo = "foo" }; use spam *; hide spam *; foo"#, + "", // we just care if it errors + ) +} + +#[test] +fn hides_alias_import_then_reimports() -> TestResult { + run_test( + r#"module spam { export alias foo = "foo" }; use spam foo; hide foo; use spam foo; foo"#, + "foo", + ) +} + #[test] fn hides_env_import_1() -> TestResult { fail_test(