sord icon indicating copy to clipboard operation
sord copied to clipboard

Add support for generic<T> syntax for type variables

Open apiology opened this issue 6 months ago • 1 comments

This is the syntax used by Solargraph for generic type variables. e.g.:

# @generic T
# @param x [generic<T>]
# @return [generic<T>]
def identity(x)
  x
end

When experienced currently, sord emits generic[T], which isn't correct RBI/RBS, and also creates issues downstream in sorbet:

rbi/checkoff.rbi:6976: Malformed type declaration. Unknown type syntax. Expected a ClassName or T.<func> https://srb.help/5004
    6976 |  sig { params(o: generic[T], type: T.class_of(generic[T])).returns(generic[T]) }
                                                                              ^^^^^^^^^^

rbi/checkoff.rbi:6976: Malformed type declaration. Unknown type syntax. Expected a ClassName or T.<func> https://srb.help/5004
    6976 |  sig { params(o: generic[T], type: T.class_of(generic[T])).returns(generic[T]) }
                            ^^^^^^^^^^

rbi/checkoff.rbi:6976: Malformed type declaration. Unknown type syntax. Expected a ClassName or T.<func> https://srb.help/5004
    6976 |  sig { params(o: generic[T], type: T.class_of(generic[T])).returns(generic[T]) }
                                                         ^^^^^^^^^^

rbi/checkoff.rbi:6976: T.class_of needs a class or module as its argument https://srb.help/5004
    6976 |  sig { params(o: generic[T], type: T.class_of(generic[T])).returns(generic[T]) }
                                              ^^^^^^^^^^^^^^^^^^^^^^
  Note:
    You may wish to use T::Class, which doesn't have this restriction.
    For more information, see https://sorbet.org/docs/class-of#tclass-vs-tclass_of
  Autocorrect: Use -a to autocorrect
    rbi/checkoff.rbi:6976: Replace with T::Class[generic[T]]
    6976 |  sig { params(o: generic[T], type: T.class_of(generic[T])).returns(generic[T]) }
                                              ^^^^^^^^^^^^^^^^^^^^^^

apiology avatar Jul 01 '25 13:07 apiology

I'll probably be back soon enough to implement the @generic tag, but I think this gets me past where I'm blocked by sord today in my workflow.

apiology avatar Jul 01 '25 13:07 apiology