From a5e22c532b074cca80d15046e6aa109d9ca79a80 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 27 Aug 2022 23:58:46 +0300 Subject: fix(tvix/eval): correctly resolve dynamic upvalues one scope up This does not yet correctly resolve them if they are more than one scope up, however. Change-Id: I6687073c60aee0282f2b6ffc98b34c1e96a60f20 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6319 Tested-by: BuildkiteCI Reviewed-by: sterni --- .../tests/tvix_tests/eval-okay-closure-with-shadowing.exp | 1 + .../tests/tvix_tests/eval-okay-closure-with-shadowing.nix | 14 ++++++++++++++ .../src/tests/tvix_tests/eval-okay-deeply-nested-with.exp | 1 + .../src/tests/tvix_tests/eval-okay-deeply-nested-with.nix | 6 ++++++ 4 files changed, 22 insertions(+) create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-closure-with-shadowing.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-closure-with-shadowing.nix create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-deeply-nested-with.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-deeply-nested-with.nix (limited to 'tvix/eval/src/tests') diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-closure-with-shadowing.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-closure-with-shadowing.exp new file mode 100644 index 000000000000..d00491fd7e5b --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-closure-with-shadowing.exp @@ -0,0 +1 @@ +1 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-closure-with-shadowing.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-closure-with-shadowing.nix new file mode 100644 index 000000000000..305463775217 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-closure-with-shadowing.nix @@ -0,0 +1,14 @@ +# If a closure closes over a variable that is statically known *and* +# available dynamically through `with`, the statically known one must +# have precedence. + +let + # introduce statically known `a` (this should be the result) + a = 1; +in + +# introduce some closure depth to force both kinds of upvalue +# resolution, and introduce a dynamically known `a` within the +# closures +let f = b: with { a = 2; }; c: a + b + c; +in f 0 0 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-deeply-nested-with.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-deeply-nested-with.exp new file mode 100644 index 000000000000..3bed31f76e3f --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-deeply-nested-with.exp @@ -0,0 +1 @@ +[ 1 2 3 4 ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-deeply-nested-with.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-deeply-nested-with.nix new file mode 100644 index 000000000000..7f1128b6707b --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-deeply-nested-with.nix @@ -0,0 +1,6 @@ +with { a = 1; b = 1; }; +with { b = 2; c = 2; }; +with { c = 3; d = 3; }; +with { d = 4; }; + +[ a b c d ] -- cgit 1.4.1