From 2dc2814d76139fb8fe927547b69f90cc066f8098 Mon Sep 17 00:00:00 2001 From: aaron <83140718+centau@users.noreply.github.com> Date: Fri, 19 Jul 2024 11:21:49 +0100 Subject: [PATCH] Fix regression with derived sources --- CHANGELOG.md | 8 ++++++++ src/graph.luau | 9 +++++---- test/tests.luau | 21 +++++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83d16e5..89cf8e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). -------------------------------------------------------------------------------- +## Unreleased + +### Fixed + +- Error stack traces being lost. + +-------------------------------------------------------------------------------- + ## [0.2.0] - 2023-11-22 ### Added diff --git a/src/graph.luau b/src/graph.luau index a90dd6c..f35b9b6 100644 --- a/src/graph.luau +++ b/src/graph.luau @@ -131,15 +131,16 @@ local update_queue = { n = 0 } :: { n: number, [number]: Node } local function evaluate_node(node: Node) if flags.strict then - local ok, cur_value, new_value + local initial_value = node.cache + for i = 1, 2 do - cur_value = node.cache + local cur_value = node.cache flush_cleanups(node) destroy_owned(node) push_scope(node) - ok, new_value = ycall(node.effect :: (T) -> T, cur_value) + local ok, new_value = ycall(node.effect :: (T) -> T, cur_value) pop_scope() if not ok then @@ -151,7 +152,7 @@ local function evaluate_node(node: Node) node.cache = new_value :: T end - return cur_value ~= new_value + return initial_value ~= node.cache else local cur_value = node.cache diff --git a/test/tests.luau b/test/tests.luau index 02e2e6c..c0f69d1 100644 --- a/test/tests.luau +++ b/test/tests.luau @@ -2261,6 +2261,27 @@ TEST("strict", wrap_root(function() src(not src()) CHECK(count == 4) end + + do CASE "effect using derived source" + local input = source(true) + + local output = derive(function() + return input() + end) + + local count = 0 + + effect(function() + output() + count += 1 + end) + + CHECK(count == 2) + + input(false) + + CHECK(count == 4) + end end)) local ok = FINISH()