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:
Jakub Žádník
2021-10-10 14:31:13 +03:00
parent 40741254f6
commit 77c520e10b
3 changed files with 44 additions and 19 deletions

View File

@ -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]);