Skip to content

Questionable semantics: list comprehension in yield expression #764

@summivox

Description

@summivox

Closest issue I can find is #667


->* yield [x for x in arr]

compiles to:

(function*(){
  var x;
  return (yield (yield* (function*(){
    var i$, ref$, len$, results$ = [];
    for (i$ = 0, len$ = (ref$ = arr).length; i$ < len$; ++i$) {
      x = ref$[i$];
      results$.push(x);
    }
    return results$;
  }())));
});

->* yield alert [x for x in arr]

compiles to:

(function*(){
  var x;
  return (yield alert((yield* (function*(){
    var i$, ref$, len$, results$ = [];
    for (i$ = 0, len$ = (ref$ = arr).length; i$ < len$; ++i$) {
      x = ref$[i$];
      results$.push(x);
    }
    return results$;
  }()))));
});

While in all cases the behavior is as expected, the compilation is surprising and undocumented. Clearly the yield* is extraneous in both cases. I suspect there must have been use cases where the yield* makes sense, but could we at least document this, and clarify when this rule is applicable?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions