Refactor scope handling and immutability

Introduces `fixed_scope_idx` to `Binder` and `Environment` to track
immutable scopes.
This allows enforcing that definitions (`def`) cannot occur in scopes
that are considered fixed or immutable, such as the global scope or the
initial bootstrap scope.
The `FunctionCompiler` is updated to use `fixed_scope_idx` and `is_root`
to determine scope immutability.
This commit is contained in:
Michael Schimmel
2026-03-12 11:22:40 +01:00
parent bb77caf1af
commit be2bef373f
4 changed files with 53 additions and 40 deletions
+3 -3
View File
@@ -778,7 +778,7 @@ mod tests {
let globals = Rc::new(RefCell::new(global_names));
let mut diag = crate::ast::diagnostics::Diagnostics::new();
let result = Binder::bind_root(globals, &expanded, &mut diag);
let result = Binder::bind_root(globals, 0, &expanded, &mut diag);
assert!(
result.is_ok(),
"Should find global '*' Error: {:?}",
@@ -803,7 +803,7 @@ mod tests {
let globals = Rc::new(RefCell::new(HashMap::new()));
let mut diag = crate::ast::diagnostics::Diagnostics::new();
let result = Binder::bind_root(globals, &expanded, &mut diag);
let result = Binder::bind_root(globals, 0, &expanded, &mut diag);
assert!(result.is_ok(), "Hygiene failed: {:?}", result.err());
}
@@ -824,7 +824,7 @@ mod tests {
let globals = Rc::new(RefCell::new(HashMap::new()));
let mut diag = crate::ast::diagnostics::Diagnostics::new();
let result = Binder::bind_root(globals, &expanded, &mut diag);
let result = Binder::bind_root(globals, 0, &expanded, &mut diag);
assert!(
result.is_ok(),
"Explicit Hygiene with Backticks failed: {:?}",