Skip to content

Commit

Permalink
Fix top-level multi-assign splat variable not working in macros (#11600)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil authored Dec 17, 2021
1 parent f13b235 commit fdcbcf4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
17 changes: 17 additions & 0 deletions spec/compiler/semantic/multi_assign_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,21 @@ describe "Semantic: multi assign" do
CR
end
end

it "can pass splat variable at top-level to macros (#11596)" do
assert_type(<<-CR) { tuple_of [int32, int32, int32] }
struct Tuple
def self.new(*args)
args
end
end
macro foo(x)
{{ x }}
end
a, *b, c = 1, 2, 3, 4, 5
foo(b)
CR
end
end
5 changes: 3 additions & 2 deletions src/compiler/crystal/semantic/top_level_visitor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -929,8 +929,9 @@ class Crystal::TopLevelVisitor < Crystal::SemanticVisitor

def visit(node : MultiAssign)
node.targets.each do |target|
if target.is_a?(Var)
@vars[target.name] = MetaVar.new(target.name)
var = target.is_a?(Splat) ? target.exp : target
if var.is_a?(Var)
@vars[var.name] = MetaVar.new(var.name)
end
target.accept self
end
Expand Down

0 comments on commit fdcbcf4

Please sign in to comment.