Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do* works differently in top-level functions vs in methods #1621

Open
bbrk24 opened this issue Nov 24, 2024 · 1 comment
Open

do* works differently in top-level functions vs in methods #1621

bbrk24 opened this issue Nov 24, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@bbrk24
Copy link
Contributor

bbrk24 commented Nov 24, 2024

At the top level:

->
  do*
   yield foo
   yield bar
// vvv
function () {
  return (function* () {
    {
      yield foo;
      yield bar;
    }
  })();
}

In a method:

{
  f()
    do*
     yield foo
     yield bar
}
// vvv
{
  *f() {
    (function* () {
      {
        yield foo;
        yield bar;
      }
    })();
  }
}

I think the latter is a bug, since it never returns or yields anything.

@edemaine edemaine added the bug Something isn't working label Nov 24, 2024
@edemaine
Copy link
Collaborator

edemaine commented Nov 24, 2024

The latter example is also missing a return, but probably because returns aren't implicit in generators.

This bug also causes getters to fail to transpile with error "Getters and setters cannot be generators":

{
  get f()
    do*
      yield foo
      yield bar
}

So we might add this to tests once fixed.

@edemaine edemaine self-assigned this Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants