Skip to content

Commit afcff0d

Browse files
Fix evaluation error when no evaluation code is provided (#1472)
* Fix invalid array access for stepper steps * Resolves bug where no execution steps will lead to access error * Add evaluation message to indicate no evaluation * Returns empty step with message * Test evaluation of empty programs in stepper --------- Co-authored-by: Martin Henz <[email protected]>
1 parent 02ff280 commit afcff0d

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/stepper/__tests__/__snapshots__/stepper.ts.snap

+2
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,8 @@ false ? 1 : 100 * factorial(100 - 1);
20952095
"
20962096
`;
20972097

2098+
exports[`Evaluation of empty code and imports Evaluate empty program 1`] = `""`;
2099+
20982100
exports[`Infinite recursion 1`] = `
20992101
"function f() {
21002102
return f();

src/stepper/__tests__/stepper.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,16 @@ describe(`#1342: Test the fix of #1341: Stepper limit off by one`, () => {
14331433
})
14341434
})
14351435

1436+
describe(`Evaluation of empty code and imports`, () => {
1437+
test('Evaluate empty program', () => {
1438+
const code = ``
1439+
const program = parse(code, mockContext())!
1440+
const steps = getEvaluationSteps(program, mockContext(), 1000)
1441+
expect(steps.map(x => codify(x[0])).join('\n')).toMatchSnapshot()
1442+
expect(getLastStepAsString(steps)).toEqual('')
1443+
})
1444+
})
1445+
14361446
// describe(`#1223: Stepper: Import statements cause errors`, () => {
14371447
// test('import a module and invoke its functions', () => {
14381448
// const code = `

src/stepper/stepper.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -3383,9 +3383,12 @@ export function getEvaluationSteps(
33833383
reducedWithPath = reduceMain(reducedWithPath[0], context)
33843384
i += 2
33853385
}
3386-
if (!limitExceeded) {
3386+
if (!limitExceeded && steps.length > 0) {
33873387
steps[steps.length - 1][2] = 'Evaluation complete'
33883388
}
3389+
if (steps.length === 0) {
3390+
steps.push([reducedWithPath[0] as es.Program, [], 'Nothing to evaluate'])
3391+
}
33893392
return steps
33903393
} catch (error) {
33913394
context.errors.push(error)

0 commit comments

Comments
 (0)