Skip to content
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

Copy docs from enum members to their helper methods (#11333) #15375

Closed
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
12 changes: 12 additions & 0 deletions spec/compiler/semantic/enum_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -613,4 +613,16 @@ describe "Semantic: enum" do
a_def = result.program.types["Foo"].lookup_defs("foo").first
a_def.previous.should be_nil
end

it "copies docs from member to helper method (#11333)" do
result = top_level_semantic <<-CRYSTAL, wants_doc: true
enum Foo
# These are the docs for `Bar`
Bar = 1
end
CRYSTAL

a_defs = result.program.types["Foo"].lookup_defs("bar?")
a_defs.first.doc.should eq("These are the docs for `Bar`")
end
end
1 change: 1 addition & 0 deletions src/compiler/crystal/semantic/top_level_visitor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@ class Crystal::TopLevelVisitor < Crystal::SemanticVisitor
method_name = is_flags ? "includes?" : "=="
body = Call.new(Var.new("self").at(member), method_name, Path.new(member.name).at(member)).at(member)
a_def = Def.new("#{member.name.underscore}?", body: body).at(member)
a_def.doc = member.doc
enum_type.add_def a_def
end

Expand Down
Loading