Skip to content

[compiler] IfExpressions and AssignmentExpressions in loop bodies #47

@wcjohnson

Description

@wcjohnson

Problem

[email protected]:
Lscdiag

f() ->
  for let i = 0; i < 10; i++:
    val = if check:
      val2 = 3
      val2
    else:
      val3 = 4
      val3

compiles to

function f() {
  for (let i = 0; i < 10; i++) {
    const val = check ? function () {
      var _ret;

      const val2 = 3;
      _ret = val2;
      return _ret;
    }() : function () {
      const val3 = 4;
      return _ret = val3;
    }();
  }
}

The generated _ret var is not in scope in the second function block, so this code will crash with a no-undef error if check is false. However, it's a mystery to me why that _ret var is being generated at all.

If the enclosing for loop is removed, the problem goes away: lscdiag

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions