about summary refs log tree commit diff
path: root/tvix/eval/src/compiler/scope.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-09-01T22·19+0300
committertazjin <tazjin@tvl.su>2022-09-08T07·59+0000
commit5ee89bcf5ca3f0b0d3b809b01ac04bf38f51d7e4 (patch)
tree1e8f3481d968b41020a2bb0fc32447dfd3e5ff7e /tvix/eval/src/compiler/scope.rs
parent0a13d267f0aa0ab1c70b6ac0e0ee8a44071b3d40 (diff)
fix(tvix/eval): inherit scope poisoning data in nested contexts r/4743
Scope poisoning must be inherited across lambda context boundaries,
e.g. if an outer scope has a poisoned `null`, any lambdas defined on
the same level must reference that poisoned identifier correctly.

Change-Id: I1aac64e1c048a6f3bacadb6d78ed295fa439e8b4
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6410
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/compiler/scope.rs')
-rw-r--r--tvix/eval/src/compiler/scope.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/tvix/eval/src/compiler/scope.rs b/tvix/eval/src/compiler/scope.rs
index b1ad4bfcd2..a50b3b7934 100644
--- a/tvix/eval/src/compiler/scope.rs
+++ b/tvix/eval/src/compiler/scope.rs
@@ -152,6 +152,15 @@ impl Scope {
         }
     }
 
+    /// Inherit scope details from a parent scope (required for
+    /// correctly nesting scopes in lambdas and thunks when special
+    /// scope features like poisoning are present).
+    pub fn inherit(&self) -> Self {
+        let mut scope = Self::default();
+        scope.poisoned_tokens = self.poisoned_tokens.clone();
+        scope
+    }
+
     /// Check whether a given token is poisoned.
     pub fn is_poisoned(&self, name: &str) -> bool {
         self.poisoned_tokens.contains_key(name)