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

Reject next, break and return with blocks. #3039

Closed
wants to merge 1 commit into from
Closed

Reject next, break and return with blocks. #3039

wants to merge 1 commit into from

Conversation

kolmogorov-fan-account
Copy link
Contributor

@kolmogorov-fan-account kolmogorov-fan-account commented Nov 30, 2015

Statements such as next [] do; end cause a segfault on latest master. This is due to the fact that it is parsed as a block_call, yet call_with_blockcannot handle these nodes. yield with a block was already rejected, so I added a bunch of similar checks for next, break and return.

Statements such as `next [] do; end` cause a segfault on latest master.
This is due to the fact that it is parsed as a block_call, yet
call_with_block cannot handle these nodes. `yield` with a block was
already rejected, so I added a bunch of similar checks for `next`,
`break` and `return`.
@kolmogorov-fan-account
Copy link
Contributor Author

kolmogorov-fan-account commented Nov 30, 2015

It seem it rejects code such as

def a(n)
  n + yield(7)
end

def b
  return a 2 do |x|
      x * 10
  end
end

puts b

that MRI handles correctly.

@clayton-shopify
Copy link
Contributor

clayton-shopify commented Nov 30, 2015

MRI does reject a 2 do |x| following a yield (with "block given to yield") so maybe it's justified for mruby to do so after next, break and return even if it's inconsistent with MRI. It's better than crashing at least.

@clayton-shopify
Copy link
Contributor

clayton-shopify commented Nov 30, 2015

In case they are helpful for testing, some other statements that presently crash mruby:

next a 0 do ; end
break a 0 do ; end
return a 0 do ; end
next {} do ; end
a a+a next yield do ; end

@matz matz closed this in c299651 Dec 1, 2015
@kolmogorov-fan-account kolmogorov-fan-account deleted the reject-next-with-block branch Dec 1, 2015
tsahara pushed a commit to iij/mruby that referenced this issue Dec 10, 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.

None yet

3 participants