Skip to content

Commit

Permalink
Fix crystal tool format visiting circular hierarchies
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Oct 7, 2024
1 parent 1f6b51d commit d2305f8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions spec/compiler/crystal/tools/unreachable_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ describe "unreachable" do
CRYSTAL
end

it "handles circular hierarchy references (#14034)" do
assert_unreachable <<-CRYSTAL
class Foo
alias Bar = Foo
end
CRYSTAL
end

it "finds initializer" do
assert_unreachable <<-CRYSTAL
class Foo
Expand Down
9 changes: 9 additions & 0 deletions src/compiler/crystal/tools/unreachable.cr
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ module Crystal
property excludes = [] of String

def process_type(type)
# Avoid visiting circular hierarchies. There's no use in processing
# alias types anyway.
# For example:
#
# struct Foo
# alias Bar = Foo
# end
return if type.is_a?(AliasType) || type.is_a?(TypeDefType)

if type.is_a?(ModuleType)
track_unused_defs type
end
Expand Down

0 comments on commit d2305f8

Please sign in to comment.