Skip to content

Commit

Permalink
Change macro var location to var node
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Aug 16, 2023
1 parent 9390ee5 commit 13e30c8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion spec/compiler/macro/macro_expander_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ describe "MacroExpander" do
assert_macro %({{node}}), "42", {node: node}, expected_pragmas: {
0 => [
Lexer::LocPushPragma.new,
Lexer::LocSetPragma.new("foo.cr", 10, 20),
Lexer::LocSetPragma.new("", 1, 19),
] of Lexer::LocPragma,
2 => [
Lexer::LocPopPragma.new,
Expand Down
15 changes: 8 additions & 7 deletions src/compiler/crystal/macros/interpreter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ module Crystal
end

def visit(node : Var)
var = @vars[node.name]?
if var
return @last = var
end
value = @vars[node.name]?

# Try to consider the var as a top-level macro call.
#
Expand All @@ -149,11 +146,15 @@ module Crystal
#
# and in this case the parser has no idea about this, so the only
# solution is to do it now.
if value = interpret_top_level_call?(Call.new(nil, node.name))
return @last = value
value ||= interpret_top_level_call?(Call.new(nil, node.name))

unless value
node.raise "undefined macro variable '#{node.name}'"
end

node.raise "undefined macro variable '#{node.name}'"
# locate the value at the place where the variable is referenced
value = value.dup.at(node)
@last = value
end

def visit(node : StringInterpolation)
Expand Down

0 comments on commit 13e30c8

Please sign in to comment.