mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 10:25:42 +02:00
Make predeclarations scoped; Add hiding tests
In some rare cases, the global predeclarations would clash, for example: > module spam { export def foo [] { "foo" } }; def foo [] { "bar" } In the example, the `foo [] { "bar" }` would get predeclared first, then the predeclaration would be overwritten and consumed by `foo [] {"foo"}` inside the module, then when parsing the actual `foo [] { "bar" }`, it would not find its predeclaration.
This commit is contained in:
@ -110,8 +110,10 @@ pub fn parse_def(
|
||||
*declaration = signature.into_block_command(block_id);
|
||||
} else {
|
||||
error = error.or_else(|| {
|
||||
// TODO: Add InternalError variant
|
||||
Some(ParseError::UnknownState(
|
||||
"Could not define hidden command".into(),
|
||||
"Internal error: Predeclaration failed to add declaration"
|
||||
.into(),
|
||||
spans[1],
|
||||
))
|
||||
});
|
||||
@ -318,7 +320,7 @@ pub fn parse_module(
|
||||
spans: &[Span],
|
||||
) -> (Statement, Option<ParseError>) {
|
||||
// TODO: Currently, module is closing over its parent scope (i.e., defs in the parent scope are
|
||||
// visible and usable in this module's scope). We might want to disable that. How?
|
||||
// visible and usable in this module's scope). We want to disable that for files.
|
||||
|
||||
let mut error = None;
|
||||
let bytes = working_set.get_span_contents(spans[0]);
|
||||
|
Reference in New Issue
Block a user