From 610b29f3e86cb1c9cb21435dce894b5da330cf4d Mon Sep 17 00:00:00 2001 From: Troy Sornson Date: Fri, 8 Aug 2025 18:26:40 -0600 Subject: [PATCH 1/2] [Bug Fix] Allow wants_docs=true to be used with full semantic processing Add spec Remove doc_comment from record macro --- spec/std/record_spec.cr | 14 ++++++++++++++ src/macros.cr | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/spec/std/record_spec.cr b/spec/std/record_spec.cr index f4034e9c2293..f1f5d9e36e33 100644 --- a/spec/std/record_spec.cr +++ b/spec/std/record_spec.cr @@ -1,4 +1,5 @@ require "spec" +require "../spec_helper" private module RecordSpec record Record1, @@ -85,4 +86,17 @@ describe "record" do it "uses the default values on the ivars" do CustomInitializer.new(__id: 10).active.should be_false end + + it "expands record macro with comments during wants_doc=true (#16074)" do + ret = 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 %} From da8901040e6514fe6ee72439808b1fd99bf6a813 Mon Sep 17 00:00:00 2001 From: Troy Sornson Date: Fri, 26 Sep 2025 20:25:38 -0600 Subject: [PATCH 2/2] Move spec to macro_spec.cr --- spec/compiler/codegen/macro_spec.cr | 13 +++++++++++++ spec/std/record_spec.cr | 14 -------------- 2 files changed, 13 insertions(+), 14 deletions(-) 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/spec/std/record_spec.cr b/spec/std/record_spec.cr index f1f5d9e36e33..f4034e9c2293 100644 --- a/spec/std/record_spec.cr +++ b/spec/std/record_spec.cr @@ -1,5 +1,4 @@ require "spec" -require "../spec_helper" private module RecordSpec record Record1, @@ -86,17 +85,4 @@ describe "record" do it "uses the default values on the ivars" do CustomInitializer.new(__id: 10).active.should be_false end - - it "expands record macro with comments during wants_doc=true (#16074)" do - ret = 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