about summary refs log tree commit diff
path: root/tvix/eval/src/compiler/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src/compiler/mod.rs')
-rw-r--r--tvix/eval/src/compiler/mod.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs
index 6ba470a7af..bf5c55db2a 100644
--- a/tvix/eval/src/compiler/mod.rs
+++ b/tvix/eval/src/compiler/mod.rs
@@ -992,12 +992,6 @@ impl Compiler {
             LocalPosition::Unknown => { /* continue below */ }
         };
 
-        // Determine whether the upvalue is a dynamic variable in the
-        // enclosing context.
-        if self.contexts[ctx_idx - 1].scope.has_with() {
-            return Some(self.add_upvalue(ctx_idx, Upvalue::Dynamic(SmolStr::new(name))));
-        }
-
         // If the upvalue comes from even further up, we need to
         // recurse to make sure that the upvalues are created at each
         // level.
@@ -1005,6 +999,13 @@ impl Compiler {
             return Some(self.add_upvalue(ctx_idx, Upvalue::Upvalue(idx)));
         }
 
+        // If the resolution of a statically known upvalue failed,
+        // attempt to resolve a dynamic one (i.e. search for enclosing
+        // `with` blocks and make that resolution dynamic).
+        if self.contexts[ctx_idx - 1].scope.has_with() {
+            return Some(self.add_upvalue(ctx_idx, Upvalue::Dynamic(SmolStr::new(name))));
+        }
+
         None
     }