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

Docs: don't show subtypes of aliased type #7124

Merged
Merged
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
31 changes: 31 additions & 0 deletions spec/compiler/crystal/tools/doc/type_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require "../../../spec_helper"

describe Doc::Type do
it "doesn't show types for alias type" do
result = semantic(%(
class Foo
class Bar
end
end

alias Alias = Foo

Alias
))

program = result.program

# Set locations to types relative to the included dir
# so they are included by the doc generator
foo_bar_type = program.types["Foo"].types["Bar"]
foo_bar_type.add_location(Location.new("./foo.cr", 1, 1))

alias_type = program.types["Alias"]
alias_type.add_location(Location.new("./foo.cr", 1, 1))

generator = Doc::Generator.new program, ["."], ".", nil

doc_alias_type = generator.type(alias_type)
doc_alias_type.types.size.should eq(0)
end
end
7 changes: 7 additions & 0 deletions src/compiler/crystal/tools/doc/generator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ class Crystal::Doc::Generator
def collect_subtypes(parent)
types = [] of Type

# AliasType has defined `types?` to be the types
# of the aliased type, but for docs we don't want
# to list the nested types for aliases.
if parent.is_a?(AliasType)
return types
end

parent.types?.try &.each_value do |type|
case type
when Const, LibType
Expand Down