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

Loop guards (`when`, `case`, `|`) don't work with `for..let` loops with `yield` (or `async`) in their bodies #1023

Closed
pepkin88 opened this Issue Mar 23, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@pepkin88
Contributor

pepkin88 commented Mar 23, 2018

Example:

fn = ->*
  obj = a: 1
  for own let k, v of obj when v % 2
    yield v

Result:

var fn;
fn = function*(){
  var obj, i$, k, v, own$ = {}.hasOwnProperty, results$ = [], fn$ = function*(k, v){
    return (yield v);
  };
  obj = {
    a: 1
  };
  for (i$ in obj) if (own$.call(obj, i$)) {
    results$.push((yield* (k = i$, v = obj[i$], v % 2 ? (fn$.call(this, k, v)) : void 8)));
  }
  return results$;
};

Expected result:

var fn;
fn = function*(){
  var obj, i$, k, v, own$ = {}.hasOwnProperty, results$ = [], fn$ = function*(k, v){
    return (yield v);
  };
  obj = {
    a: 1
  };
  for (i$ in obj) if (own$.call(obj, i$)) {
    if (obj[i$] % 2) {
      results$.push((yield* (k = i$, v = obj[i$], v % 2 ? (fn$.call(this, k, v)) : void 8)));
    }
  }
  return results$;
};

I chose an example with own, because it also inserts its own kind of guard and it seems to be working correctly. A guard for a loop with async doesn't work either, but I think it's related to #1021.

Other for..let variants seem to be OK, those with an else block too.

@rhendric rhendric added the bug label Mar 26, 2018

@rhendric

This comment has been minimized.

Collaborator

rhendric commented Mar 26, 2018

Also another effect of #1019.

@pepkin88

This comment has been minimized.

Contributor

pepkin88 commented Jul 30, 2018

Now I noticed, that that code doesn't work, but from different reasons. The guard v % 2 is indeed inserted, but in the wrong spot. But, as you predicted, fix for #1019 (#1060) fixes it too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment