How to hint Sorbet with const_get and dynamic parent class?

639 views Asked by At

How can I allow a class's parent to be dynamically defined and pass Sorbet type checking?

For example:


class A; end

class B < Object.const_get("A"); end

This is part of a Rails gem that requires configuring the base class of a model, similar to Devise configuring a parent controller class.

When running this, srb tc returns the error: Superclasses must only contain constant literals https://srb.help/4002

Alternatively, I have tried hinting:

class A; end

class B < T.let(Object.const_get("A"), A); end

...which results in type-checking errors like Method some_method does not exist on T.class_of(B) https://srb.help/7003, and srb rbi hidden-definitions throws this error:

ruby/gems/2.7.0/gems/sorbet-runtime-0.5.6371/lib/types/private/casts.rb:23:in `cast': T.let: Expected type A, got type Class with value A (TypeError)
0

There are 0 answers