diff --git a/spec/compiler/macro/macro_methods_spec.cr b/spec/compiler/macro/macro_methods_spec.cr index 76d5f795903c..f25e2159b5e6 100644 --- a/spec/compiler/macro/macro_methods_spec.cr +++ b/spec/compiler/macro/macro_methods_spec.cr @@ -121,6 +121,14 @@ module Crystal it "expands macro with id call on number" do assert_macro "{{x.id}}", %(1), {x: 1.int32} end + + it "expands macro with id call on path" do + assert_macro "{{x.id}}", %(Foo), {x: Path.new("Foo")} + end + + it "expands macro with id call on global path" do + assert_macro "{{x.id}}", %(::Foo), {x: Path.new("Foo", global: true)} + end end it "executes == on numbers (true)" do diff --git a/src/compiler/crystal/macros/methods.cr b/src/compiler/crystal/macros/methods.cr index 9891c4cc2b2a..f92c9aa766c6 100644 --- a/src/compiler/crystal/macros/methods.cr +++ b/src/compiler/crystal/macros/methods.cr @@ -2388,7 +2388,11 @@ module Crystal end def to_macro_id - @names.join "::" + String.build do |io| + io << "::" if global? + + @names.join(io, "::") + end end end