diff --git a/CHANGELOG.md b/CHANGELOG.md index affdfd894..67d3205a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ We'll note all notable changes in this file, including bug fixes, enhancements, and all closed issues. Dates are in `YYYY-MM-DD` format and versions are in [semantic versioning](http://semver.org/) format. +## 0.10.8 2024-08-03 + +### Fixed + +- Repaired borrowed bindings from other sources. + ## 0.10.7 2024-07-27 ### Added diff --git a/src/nodes/Borrow.test.ts b/src/nodes/Borrow.test.ts index 6347ca3f3..60a334d32 100644 --- a/src/nodes/Borrow.test.ts +++ b/src/nodes/Borrow.test.ts @@ -17,6 +17,13 @@ Time() [`0`], '0', ], + [ + `↓ sup1.a + a + `, + [`↑ a: 0`], + '0', + ], ])('Expect %s to be %s', (code, supplements, value) => { expect(evaluateCode(code, supplements)?.toString()).toBe(value); }); diff --git a/src/nodes/Program.ts b/src/nodes/Program.ts index 61fcfdcec..5e184b276 100644 --- a/src/nodes/Program.ts +++ b/src/nodes/Program.ts @@ -117,11 +117,14 @@ export default class Program extends Expression { const [source, definition] = borrow.getShare(context) ?? []; if (source === undefined) { if (definition !== undefined) definitions.push(definition); - } else + } else { definitions.push( definition === undefined ? source : definition, ); + definitions.push(source); + } } + // Return all of the imported definitions and any sources that are part of a named import return definitions; } diff --git a/src/runtime/Evaluator.ts b/src/runtime/Evaluator.ts index 590b7c8f5..1dbdb68a6 100644 --- a/src/runtime/Evaluator.ts +++ b/src/runtime/Evaluator.ts @@ -93,8 +93,8 @@ export default class Evaluator { /** This represents a stack of node evaluations. The first element of the stack is the currently evaluating node. */ readonly evaluations: Evaluation[] = []; - /** The last evaluation to be removed from the stack */ - #lastEvaluation: Evaluation | undefined; + /** The last evaluation to be removed from the stack not triggered by source, used to get shared bindings from a source's block. */ + #lastSourceEvaluation: Evaluation | undefined; /** The callback to notify if the evaluation's value changes. */ readonly observers: EvaluationObserver[] = []; @@ -444,7 +444,7 @@ export default class Evaluator { } getLastEvaluation() { - return this.#lastEvaluation; + return this.#lastSourceEvaluation; } getCurrentClosure() { @@ -688,7 +688,7 @@ export default class Evaluator { // Reset the evluation stack. this.evaluations.length = 0; - this.#lastEvaluation = undefined; + this.#lastSourceEvaluation = undefined; // Didn't recently step to node. this.#steppedToNode = false; @@ -1638,7 +1638,9 @@ export default class Evaluator { throw Error( "Shouldn't be possible to end an evaluation on an empty evaluation stack.", ); - this.#lastEvaluation = evaluation; + // We want to remember the block and it's bindings for borrowing, since the source's evaluation doesn't have any bindings. + if (!(evaluation.getDefinition() instanceof Source)) + this.#lastSourceEvaluation = evaluation; const def = evaluation.getDefinition(); if (def instanceof Source) { // If not in the past, save the source value.