Skip to content

Commit 033d951

Browse files
authored
Merge pull request #2424 from Shopify/uk-fix-module-patching
Fully qualify references to top-level `Module`
2 parents 770e8e2 + 3db55af commit 033d951

3 files changed

Lines changed: 7 additions & 18 deletions

File tree

lib/tapioca/runtime/trackers/required_ancestor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def required_ancestors_by(mod)
5252

5353
module T
5454
module Helpers
55-
prepend(Module.new do
55+
prepend(::Module.new do
5656
def requires_ancestor(&block)
5757
# We can't directly call the block since the ancestor might not be loaded yet.
5858
# We save the block in the map and will resolve it later.

lib/tapioca/sorbet_ext/generic_name_patch.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def type_member(variance = :invariant, &bounds_proc)
2222
# `T::Generic#type_member` just instantiates a `T::Type::TypeMember` instance and returns it.
2323
# We use that when registering the type member and then later return it from this method.
2424
Tapioca::TypeVariableModule.new(
25-
T.cast(self, Module),
25+
T.cast(self, ::Module),
2626
Tapioca::TypeVariableModule::Type::Member,
2727
variance,
2828
bounds_proc,
@@ -35,7 +35,7 @@ def type_template(variance = :invariant, &bounds_proc)
3535
# `T::Generic#type_template` just instantiates a `T::Type::TypeTemplate` instance and returns it.
3636
# We use that when registering the type template and then later return it from this method.
3737
Tapioca::TypeVariableModule.new(
38-
T.cast(self, Module),
38+
T.cast(self, ::Module),
3939
Tapioca::TypeVariableModule::Type::Template,
4040
variance,
4141
bounds_proc,
@@ -48,7 +48,7 @@ def has_attached_class!(variance = :invariant, &bounds_proc)
4848
Tapioca::Runtime::GenericTypeRegistry.register_type_variable(
4949
self,
5050
Tapioca::TypeVariableModule.new(
51-
T.cast(self, Module),
51+
T.cast(self, ::Module),
5252
Tapioca::TypeVariableModule::Type::HasAttachedClass,
5353
variance,
5454
bounds_proc,

lib/tapioca/sorbet_ext/name_patch.rb

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,13 @@ module T
55
module Types
66
class Simple
77
module NamePatch
8-
NAME_METHOD = Module.instance_method(:name) #: UnboundMethod
9-
108
def name
119
# Sorbet memoizes this method into the `@name` instance variable but
1210
# doing so means that types get memoized before this patch is applied
13-
qualified_name_of(@raw_type)
14-
end
15-
16-
def qualified_name_of(constant)
17-
name = NAME_METHOD.bind_call(constant)
18-
name = nil if name&.start_with?("#<")
19-
return "::T.untyped" if name.nil?
11+
name = Tapioca::Runtime::Reflection.qualified_name_of(@raw_type)
12+
name = "::T.untyped" if name.nil?
2013

21-
if name.start_with?("::")
22-
name
23-
else
24-
"::#{name}"
25-
end
14+
name
2615
end
2716
end
2817

0 commit comments

Comments
 (0)