Skip to content

REPL: Generator was advanced before hitting ENTER #61390

@ye-yu

Description

@ye-yu

Version

v22.19.0

Platform

Microsoft Windows NT 10.0.26100.0 x64

Subsystem

REPL

What steps will reproduce the bug?

In REPL, prepare a generator function

function* infinite() {
  let i = 0;
  while (true) {
    i += 1;
    yield {
      i,
      reset: () => {
        i = 0;
      },
    };
  }
}

Instantiate and get next value

> inf = infinite()
Object [Generator] {}
> inf.next().value
{ i: 7, reset: [Function: reset] }
> inf.next().value
{ i: 12, reset: [Function: reset] }
> inf.next().value
{ i: 15, reset: [Function: reset] }
> inf.next().value
{ i: 18, reset: [Function: reset] }
> inf.next().value
{ i: 21, reset: [Function: reset] }
> inf.next().value.reset()
undefined
> inf.next().value
{ i: 3, reset: [Function: reset] }
> inf.next().value
{ i: 6, reset: [Function: reset] }

How often does it reproduce? Is there a required condition?

Always. The statement should be executed one by one.

However, if multiple .next statements are called in a single line, the numbers are generated in the correct incrementation.

> inf = infinite(); Array.from({ length: 10 }).map(e => inf.next().value.i)
[
  1, 2, 3, 4,  5,
  6, 7, 8, 9, 10
]

What is the expected behavior? Why is that the expected behavior?

When executing inf.next().value, REPL should return 1, 2, 3, 4...

When calling the reset function, the iteration should reset to 1, 2, 3, 4...

What do you see instead?

Iteration did not start from 1. The next number was incremented by 3 instead of 1.

Additional information

(AI said the REPL is advancing the generator to get the preview value, of which) When I press the UP button to get the last executed command and then DOWN and then UP once more, the generator was advanced further than just incremental of 3

Metadata

Metadata

Assignees

No one assigned

    Labels

    replIssues and PRs related to the REPL subsystem.v22.xIssues that can be reproduced on v22.x or PRs targeting the v22.x-staging branch.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions