diff --git a/spec/compiler/codegen/macro_spec.cr b/spec/compiler/codegen/macro_spec.cr index ea359b00c6b6..a3cb8754ef3c 100644 --- a/spec/compiler/codegen/macro_spec.cr +++ b/spec/compiler/codegen/macro_spec.cr @@ -1889,4 +1889,17 @@ describe "Code gen: macro" do run("{{ flag?(:foo) ? 1 : 0 }}", flags: %w(foo)).to_i.should eq(1) run("{{ flag?(:foo) ? 1 : 0 }}", Int32, flags: %w(foo)).should eq(1) end + + it "expands record macro with comments during wants_doc=true (#16074)" do + semantic(<<-CRYSTAL, wants_doc: true) + require "macros" + require "object/properties" + + record TestRecord, + # This is a comment + test : String? + + TestRecord.new("test").test + CRYSTAL + end end diff --git a/src/macros.cr b/src/macros.cr index c01a5d35e391..9a44cacce236 100644 --- a/src/macros.cr +++ b/src/macros.cr @@ -73,11 +73,11 @@ macro record(__name name, *properties, **kwargs) struct {{name.id}} {% for property in properties %} {% if property.is_a?(Assign) %} - getter {{property.target.id}} + getter({{property.target.id}}) {% elsif property.is_a?(TypeDeclaration) %} - getter {{property}} + getter({{property}}) {% else %} - getter :{{property.id}} + getter(:{{property.id}}) {% end %} {% end %}