Skip to content
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
19 changes: 17 additions & 2 deletions lib/typeprof/analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -549,12 +549,27 @@ def get_class_name(klass)
if klass == Type.any
"???"
else
path = @class_defs[klass.idx].name
class_def = @class_defs[klass.idx]
path = class_def.name
if @namespace
# Find index where namespace and path don't match anymore
i = 0
i += 1 while @namespace[i] && @namespace[i] == path[i]
if path[i]
path[i..].join("::")
parts = path[i..]

# Sometimes stripping off matching parts of the namespace can lead to matching the wrong
# class so we check here and fully qualify in a case of a mismatch
mismatched = (0..i).any? do |j|
search_path = @namespace[0..j] + parts
found = @class_defs.map { |(_, cd)| cd }.find { |cd| cd.name == search_path }
found && found != class_def
end

# Use the full path and add an empty field to cause leading ::
parts = [""] + path if mismatched

parts.join("::")
else
path.last.to_s
end
Expand Down
14 changes: 14 additions & 0 deletions smoke/rbs-base-namespace.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Qux
module Foo
class Bar < ::Foo::Bar
end
end
end
__END__
# Classes
module Qux
module Foo
class Bar < ::Foo::Bar

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, this would be missing the leading ::

end
end
end
5 changes: 5 additions & 0 deletions smoke/rbs-base-namespace.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Foo
class Bar
end
end