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

Nested captured block looses scope and crashes compiler #227

Closed
jhass opened this issue Oct 12, 2014 · 4 comments
Closed

Nested captured block looses scope and crashes compiler #227

jhass opened this issue Oct 12, 2014 · 4 comments

Comments

@jhass
Copy link
Member

jhass commented Oct 12, 2014

def foo(&block)
  block.call
end

foo {
  a = "foo"
  foo {
    a.upcase
  }
}
@asterite
Copy link
Member

Apparently the first block is considered a closure by the compiler, which is wrong. It'll be a good opportunity to clean up the closure detection algorithm, which is rather ugly now :-)

@jhass
Copy link
Member Author

jhass commented Oct 13, 2014

I guess this is the same one:

def foo(&block)
  block.call
end

foo do
  a = 1.5
  ->(x : Int32) { x + a }
end

@asterite
Copy link
Member

Here's the smallest one that crashes the compiler:

->{ a = 1; ->{ a } }

Basically, a proc inside another one, the nested one being a closure inside the outer one. But the compiler thinks the outer one forms a closure over a, which is wrong, and then the codegen doesn't expect this and crashes.

I think it's easy to fix but I'd like to refactor some things while fixing this so the code is clearer.

@jhass
Copy link
Member Author

jhass commented Oct 14, 2014

Sure, take your time.

asterite pushed a commit that referenced this issue Oct 14, 2014
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

No branches or pull requests

2 participants