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

RFC: evaluate for iterator in outer scope #23387

Merged
merged 1 commit into from
Aug 22, 2017
Merged

RFC: evaluate for iterator in outer scope #23387

merged 1 commit into from
Aug 22, 2017

Conversation

JeffBezanson
Copy link
Member

Since it's scope season, here's another issue that, in a way, is the flip side of #22659.

Reasoning by the following transformation:

for i in itr
    body
end

to

foreach(i->body, itr)

itr should be evaluated in the surrounding scope. However, we currently enclose the entire for loop in a new scope, in addition to the per-iteration scope. I believe this is unnecessary.

The breakage here is extremely minor, since for this to matter you basically have to write for i in (a = b), which nobody ever does. Code that does do that is likely to keep working, since you can still see a inside the loop.

@JeffBezanson JeffBezanson added breaking This change will break code compiler:lowering Syntax lowering (compiler front end, 2nd stage) labels Aug 22, 2017
@JeffBezanson JeffBezanson merged commit fa87185 into master Aug 22, 2017
@JeffBezanson JeffBezanson deleted the jb/forscope branch August 22, 2017 17:35
@StefanKarpinski
Copy link
Member

Itchy trigger-finger, huh? But it's a good change, so 👍 .

@JeffBezanson
Copy link
Member Author

I have a follow-up that conflicts with it :)

JeffBezanson added a commit that referenced this pull request Aug 22, 2017
also remove the outer scope "wrapper" from `while` loops, similar to #23387
JeffBezanson added a commit that referenced this pull request Aug 25, 2017
also remove the outer scope "wrapper" from `while` loops, similar to #23387
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This change will break code compiler:lowering Syntax lowering (compiler front end, 2nd stage)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants