Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add location to result from macro method interpretation #15213

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions spec/compiler/macro/macro_methods_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,10 @@ module Crystal
assert_macro %({{[1, 2, 3].map { |e| e == 2 }}}), "[false, true, false]"
end

it "executes map assigns location" do
assert_macro %({{[1].map { |e| e }.filename }}), %("")
end

it "executes reduce with no initial value" do
assert_macro %({{[1, 2, 3].reduce { |acc, val| acc * val }}}), "6"
end
Expand Down
1 change: 1 addition & 0 deletions src/compiler/crystal/macros/interpreter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ module Crystal
rescue ex
node.raise ex.message
end
@last.location ||= node.name_location
else
# no receiver: special calls
# may raise `Crystal::TopLevelMacroRaiseException`
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/macros/methods.cr
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ module Crystal
def interpret(method : String, args : Array(ASTNode), named_args : Hash(String, ASTNode)?, block : Crystal::Block?, interpreter : Crystal::MacroInterpreter, name_loc : Location?)
case method
when "id"
interpret_check_args { MacroId.new(to_macro_id) }
interpret_check_args { MacroId.new(to_macro_id).at(location) }
when "stringify"
interpret_check_args { stringify }
when "symbolize"
Expand Down
Loading