Infinite recursion bug when referencing generic class in a sig
on its .inherited
method
#1634
Labels
bug
Something isn't working
sig
on its .inherited
method
#1634
Issue
Referencing a generic class inside of the
sig
of its own.inherited
method will cause infinite recursion:tapioca dsl --verify
crashes with aSystemStackError
Sample abridged backtrace
Example
Now that
T::Class
is generic over its attached class (see sorbet/sorbet#6781), this code isn't valid:The developer might then try to use a specific class type to fix it:
This will cause the issue. A workaround would be to use a non-specific class type:
Here's a unit test that reproduces the issue:
392fbf6#diff-5a7c31a7504b1e445b8c319f9d3fcde2966c06f2f50bc66fd3d38605a565e02aR137-R140
Further details
At the time
MyGenericClass[T.anything]
is referenced from the sig,MyGenericClass
doesn't exist in theGenericTypeRegistry
yet. The[]
will try to look up the class in the registry, see that it's not there, and start thecreate_generic_type
. In doing so, it'll attempt to evaluate the sig, which recurses infinitely.I'm not sure what the right way to handle this is, but I see a few possibilities, most of which are pretty complicated.
.inherited
..inherited
, which evaluates them in a way that doesn't hit the recursion. I'm not sure what that might look like.I welcome any other suggestions!
The text was updated successfully, but these errors were encountered: