Skip to content

Commit

Permalink
Use qualified name for types
Browse files Browse the repository at this point in the history
Qualified name specifies the name from the root namespace. This will prevent errors in the future where we have clashing constant names that were separated by their fully qualified names. During RBI generation we used to drop the leading `::` anchors and the constant would point to a wrong type than what the developer intended.

e.g. #466
  • Loading branch information
KaanOzkan committed Sep 1, 2021
1 parent 4d88189 commit d90525d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/tapioca/sorbet_ext/name_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,22 @@ module Types
class Simple
module NamePatch
def name
@name ||= ::Tapioca::Reflection.name_of(@raw_type).freeze
@qualified_name ||= qualified_name_of(@raw_type).freeze
end

private

NAME_METHOD = Module.instance_method(:name)

def qualified_name_of(constant)
name = NAME_METHOD.bind(constant).call
return if name.nil?

if name.start_with?("::")
name
else
"::#{name}"
end
end
end

Expand Down

0 comments on commit d90525d

Please sign in to comment.