Skip to content
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

Fix issue with nested with loops #214

Closed
wants to merge 2 commits into from
Closed

Conversation

geomaster
Copy link
Contributor

When compiling code such as the following:

with a
  with .b
    print .c

The correct output should be roughly equivalent to print a.b.c. However, this is not the case, and moonc bombs with an error when code like this is run, even in the presence of a suitable table structure (so that a.b.c is defined).
This is because moonc currently compiles the above snippet into this (note the _with_1.b part):

do
  local _with_0 = a
  do 
    local _with_1 = _with_1.b
    print _with_1.c
  end
end

This happens because when the transformer emits the _with_1 assignment, scope_var (which is used by values to look up the current scope when the short-dot syntax is used) has already been set to the new one (from the nested block). This fix simply reorders the scope_var assignment so that it happens after these statements have been emitted, so the correct scope is being used.
This PR fixes #187 (and #197, its dupe).

Nested `with` blocks, when the node being used for the block is
referenced from the enclosing `with` block using the short-dot syntax,
do not produce the correct output. This happens because `scoped_var` is
being set at the wrong place. Fixes leafo#187 (and leafo#197, its dupe).
Added two tests that test the behavior of nested `with` blocks. When a
nested `with` block is started, using a variable referenced from the
enclosing one, expected behavior is to change the short-dot syntax scope
to the newly-referenced variable.
@leafo
Copy link
Owner

leafo commented Sep 26, 2015

Hey, sorry for the delay. Just manually merged in the patch. Thanks for taking the time to fix it.

@leafo leafo closed this Sep 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

With with with inside with is broken.
2 participants