From 4d827b4e57a9d3e15d10fba88a227cd93c994ba3 Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Tue, 21 Aug 2018 23:34:28 -0300 Subject: [PATCH] Macros: evaluate yield expressions --- spec/compiler/semantic/macro_spec.cr | 12 ++++++++++++ src/compiler/crystal/macros/interpreter.cr | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/compiler/semantic/macro_spec.cr b/spec/compiler/semantic/macro_spec.cr index 836744b5783b..32d2d4761d09 100644 --- a/spec/compiler/semantic/macro_spec.cr +++ b/spec/compiler/semantic/macro_spec.cr @@ -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 diff --git a/src/compiler/crystal/macros/interpreter.cr b/src/compiler/crystal/macros/interpreter.cr index 09ced3441ffe..d7447704ad6c 100644 --- a/src/compiler/crystal/macros/interpreter.cr +++ b/src/compiler/crystal/macros/interpreter.cr @@ -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