-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[Bug Fix] Allow wants_docs=true to be used with full semantic processing #16172
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
base: master
Are you sure you want to change the base?
Conversation
Add spec Remove doc_comment from record macro
Hm, nope, same build problems already :/ Whelp, I'm confused. The lint error makes sense... Is it the call to |
Ah dang, it's the
|
TestRecord.new("test").test | ||
CRYSTAL | ||
end |
There was a problem hiding this comment.
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 🤷
There was a problem hiding this comment.
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
?
I toyed with the record Foo,
# this is a multiline
# comment
name : String? Would be expanded as: getter(# This is a multiline
# comment
name : String | ::Nil) And semantics with There's no diff --git a/spec/compiler/semantic/doc_spec.cr b/spec/compiler/semantic/doc_spec.cr
index af14b85a7..22ede5a48 100644
--- a/spec/compiler/semantic/doc_spec.cr
+++ b/spec/compiler/semantic/doc_spec.cr
@@ -675,4 +675,21 @@ describe "Semantic: doc" do
a_def.doc.should eq("Some description")
end
end
+
+ it "expands record macro with comments (#16074)" do
+ result = semantic <<-CRYSTAL, wants_doc: true
+ require "macros"
+ require "object/properties"
+
+ record Foo,
+ # This is a multiline
+ # comment
+ name : String?
+
+ Foo.new("test").name
+ CRYSTAL
+
+ a_def = result.program.types["Foo"].lookup_defs("name").first
+ a_def.doc.should eq("This is a multiline\ncomment")
+ end
end
diff --git a/src/macros.cr b/src/macros.cr
index c01a5d35e..a168f9c80 100644
--- a/src/macros.cr
+++ b/src/macros.cr
@@ -75,7 +75,8 @@ macro record(__name name, *properties, **kwargs)
{% if property.is_a?(Assign) %}
getter {{property.target.id}}
{% elsif property.is_a?(TypeDeclaration) %}
- getter {{property}}
+ {% unless property.doc == "" %}# {{property.doc.gsub(/\n/, "\n# ").id}}{% end %}
+ getter {{property.var.id}} : {{property.type}} {% if property.value %} = {{property.value}} {% end %}
{% else %}
getter :{{property.id}}
{% end %} |
This triggers another bug because Weirdly Here's the fixed patch: diff --git a/src/macros.cr b/src/macros.cr
index c01a5d35e..59b6c57f8 100644
--- a/src/macros.cr
+++ b/src/macros.cr
@@ -75,7 +75,8 @@ macro record(__name name, *properties, **kwargs)
{% if property.is_a?(Assign) %}
getter {{property.target.id}}
{% elsif property.is_a?(TypeDeclaration) %}
- getter {{property}}
+ {% unless property.doc == "" %}# {{property.doc.gsub(/\n/, "\n# ").id}}{% end %}
+ getter {{property.var.id}} : {{property.type}}{% if !property.value.nil? || property.value.stringify == "nil" %} = {{property.value}}{% end %}
{% else %}
getter :{{property.id}}
{% end %} It shall also add some specs to |
This is another attempt at addressing this bug from #16074. Previous PR was suffering from perpetual build failures that looked unrelated to my changes, so trying again! Sorry for the PR spam! 😅