Skip to content

Commit 392fbf6

Browse files
committed
Add characterization test for “.inhertited” bug
1 parent 5a1b364 commit 392fbf6

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

spec/tapioca/runtime/generic_type_registry_spec.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ class GenericTypeRegistrySpec < Minitest::Spec
7777
refute_same(result, RaisesInInheritedCallback)
7878
assert_operator(result, :<, RaisesInInheritedCallback)
7979
end
80+
81+
it "works for classes that specify a 'loose' sig on .inherited" do
82+
# By "loose", we mean `T::Class[T.anything]` instead of `T::Class[SampleGenericClass[T.anything]]`
83+
_ = HasNonRecursiveInheritedSig[Object]
84+
end
85+
86+
it "FIXME: breaks from infinite recursion if the sig on .inherited uses the generic type" do
87+
assert_raises(SystemStackError) do
88+
HasRecursiveInheritedSig[Object]
89+
end
90+
end
8091
end
8192
end
8293

@@ -98,6 +109,37 @@ def inherited(subclass)
98109
end
99110
end
100111
end
112+
113+
class HasNonRecursiveInheritedSig
114+
extend T::Generic
115+
116+
Element = type_member
117+
118+
class << self
119+
extend T::Sig
120+
121+
# The correct type would be `T::Class[SampleGenericClass[T.anything]]` not honey, that's recursion Pooh!
122+
sig { params(subclass: T::Class[T.anything]).void }
123+
def inherited(subclass)
124+
super
125+
end
126+
end
127+
end
128+
129+
class HasRecursiveInheritedSig
130+
extend T::Generic
131+
132+
Element = type_member
133+
134+
class << self
135+
extend T::Sig
136+
137+
sig { params(subclass: T::Class[HasRecursiveInheritedSig[T.anything]]).void }
138+
def inherited(subclass)
139+
super
140+
end
141+
end
142+
end
101143
end
102144
end
103145
end

0 commit comments

Comments
 (0)