Skip to content

Commit

Permalink
Macros: evaluate yield expressions (#6587)
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite authored and RX14 committed Aug 22, 2018
1 parent ea543f3 commit 5e059ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions spec/compiler/semantic/macro_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1321,4 +1321,16 @@ describe "Semantic: macro" do
{% end %}
)) { int32 }
end

it "evaluates yield expression (#2924)" do
assert_type(%(
macro a(b)
{{yield b}}
end
a("foo") do |c|
{{c}}
end
)) { string }
end
end
2 changes: 1 addition & 1 deletion src/compiler/crystal/macros/interpreter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ module Crystal
block_vars = {} of String => ASTNode
node.exps.each_with_index do |exp, i|
if block_arg = block.args[i]?
block_vars[block_arg.name] = exp.clone
block_vars[block_arg.name] = accept exp.clone
end
end
@last = replace_block_vars block.body.clone, block_vars
Expand Down

0 comments on commit 5e059ab

Please sign in to comment.