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 crystal playground cannot yield with one parameter #4527

Closed
wants to merge 1 commit into from
Closed

fix crystal playground cannot yield with one parameter #4527

wants to merge 1 commit into from

Conversation

akiicat
Copy link
Contributor

@akiicat akiicat commented Jun 7, 2017

Fix #4526

@@ -469,7 +469,7 @@ describe Playground::AgentInstrumentorTransformer do
end
), <<-CR
def foo(x)
yield _p.i(3) { x }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From $ crystal play -v i see that the instrumented code for

def foo(x)
  yield x
end
foo(3) do |a|
  a
end

is

def foo(x)
  yield _p.i(2) do
    x
  end
end
_p.i(4) do
  foo(3) do |a|
    _p.i(5) do
      a
    end
  end
end

which does not compile. The to_s of the code uses begin; x; end instead of { x } for the block.

So there is actually a bug in the Crystal::ToSVisitor for printing yields with calls with block. begin/end should be avoided and { ... } should be used to preserve semantics OR a begin/end should wrap the call:

def foo(x)
  yield begin
    _p.i(3) do
      x
    end
  end
end

I would rather not remove the instrumentation for single argument yields. The best thing would be to fix the ToSVisitor. The second best is to change the agent_instrumentor_transformer.cr to explicitly wrap the instrument(...) with a begin/end.

@asterite
Copy link
Member

asterite commented Jun 7, 2017

Fixed by b7e9237

@asterite asterite closed this Jun 7, 2017
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.

3 participants