Skip to content

[compiler] IfExpressions and AssignmentExpressions in loop bodies #47

Open

Description

@wcjohnson

Problem

lightscript@0.5.9:
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

Activity

  1. wcjohnson commented on Sep 24, 2017

    @wcjohnson
    Author

    Apparently I fixed this at some point in my 2.x branch, because it's not an issue with compiler: latest: lscdiag

    I'm guessing it's related with the statementsToExpressions issue that was ultimately responsible for #40

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

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