Skip to content
Open
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
13 changes: 13 additions & 0 deletions spec/compiler/codegen/macro_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's the best spot, but it was somewhere testing macros and already included the spec_helper.cr file that was previously causing problems 🤷

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, only the compiler specs are meant to include spec/spec_helper. It basically requires the compiler, and we don't want to inject it into std specs (and apparently it doesn't work).

Now, it's not a codegen issue but a semantic issue, so it should be under spec/compiler/semantic. It's related to docs, so maybe spec/compiler/semantic/doc_spec.cr?

end
6 changes: 3 additions & 3 deletions src/macros.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

Expand Down
Loading