Skip to content

Commit

Permalink
Copy docs from enum members to their helper methods (crystal-lang#11333)
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodywasishere committed Jan 26, 2025
1 parent 9e475f6 commit 1e3aac8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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

0 comments on commit 1e3aac8

Please sign in to comment.