Skip to content

Commit

Permalink
Merge pull request #5138 from crystal-lang/bug/block-arg-underscore
Browse files Browse the repository at this point in the history
Codegen: don't assign yield exp to underscore block arguments
  • Loading branch information
asterite committed Oct 17, 2017
2 parents 181986d + a4ddfea commit a6ddeb3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions spec/compiler/codegen/block_spec.cr
Expand Up @@ -1509,4 +1509,13 @@ describe "Code gen: block" do
a + b
)).to_i.should eq(3)
end

it "codegens block with repeated underscore and different types (#4711)" do
codegen(%(
def foo
yield('0', 0)
end
foo{|_, _| }
))
end
end
4 changes: 2 additions & 2 deletions src/compiler/crystal/codegen/codegen.cr
Expand Up @@ -1407,7 +1407,7 @@ module Crystal
exp_value = exp_values.first[0]
exp_type.tuple_types.each_with_index do |tuple_type, i|
arg = block.args[i]?
if arg
if arg && arg.name != "_"
t_type = tuple_type
t_value = codegen_tuple_indexer(exp_type, exp_value, i)
block_var = block_context.vars[arg.name]
Expand All @@ -1416,7 +1416,7 @@ module Crystal
end
else
exp_values.each_with_index do |(exp_value, exp_type), i|
if arg = block.args[i]?
if (arg = block.args[i]?) && arg.name != "_"
block_var = block_context.vars[arg.name]
assign block_var.pointer, block_var.type, exp_type, exp_value
end
Expand Down

0 comments on commit a6ddeb3

Please sign in to comment.