Skip to content

Returning from inside a with statement? #208

Description

@Awpteamoose

So the following code:

(arg1, arg2) ->
    with table_with_functions
        return {
            .fn1("work")
            .fn2("more work")
        }

My intent is to have a function return a table that is filled with values returned by functions inside table_with_functions.

Compiles fine, generates the following code:

return function(arg1, arg2)
  do
    local _with_0 = table_with_functions
    return {
      _with_0.fn1("work"),
      _with_0.fn2("more work")
    }
    return _with_0
  end
end

That last return is not valid Lua and it doesn't work.

I've ended up writing it like such:

(arg1, arg2) ->
    with table_with_functions
        return {
            .fn1("work")
            .fn2("more work")
        }
    local _

But that just seems like a hack to avoid implicit return.


Am I doing something wrong? Is there a better way? I've only been using MoonScript for about two days so I might've missed something.

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions