AaronC81 / sord

Convert YARD docs to Sorbet RBI and Ruby 3/Steep RBS files
https://sord.aaronc.cc
MIT License
299 stars 18 forks source link

Elem constant generation #93

Open connorshea opened 5 years ago

connorshea commented 5 years ago

Is your feature request related to a problem? Please describe. A lot of the remaining errors returned by rake examples:typecheck are to do with classes descending from Array or Struct, and thus needing to have the Elem constant redeclared.

sord_examples/yard.rbi:4248: Type Elem declared by parent Array must be re-declared in YARD::Parser::Ruby::Legacy::TokenList https://srb.help/5036
    4248 |        class TokenList < Array
                  ^^^^^^^^^^^^^^^^^^^^^^^
    https://github.com/sorbet/sorbet/tree/7afa6f30e4d5f6e6e49815ff130d6c98563df809/rbi/core/array.rbi#L7: Elem declared in parent here
     7 |  Elem = type_member(:out)
          ^^^^^^^^^^^^^^^^^^^^^^^^

sord_examples/yard.rbi:4296: Type Elem declared by parent Array must be re-declared in YARD::Parser::Ruby::Legacy::StatementList https://srb.help/5036
    4296 |        class StatementList < Array
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    https://github.com/sorbet/sorbet/tree/7afa6f30e4d5f6e6e49815ff130d6c98563df809/rbi/core/array.rbi#L7: Elem declared in parent here
     7 |  Elem = type_member(:out)
          ^^^^^^^^^^^^^^^^^^^^^^^^

sord_examples/yard.rbi:4361: Type Elem declared by parent Array must be re-declared in YARD::Parser::Ruby::AstNode https://srb.help/5036
    4361 |      class AstNode < Array
                ^^^^^^^^^^^^^^^^^^^^^
    https://github.com/sorbet/sorbet/tree/7afa6f30e4d5f6e6e49815ff130d6c98563df809/rbi/core/array.rbi#L7: Elem declared in parent here
     7 |  Elem = type_member(:out)
          ^^^^^^^^^^^^^^^^^^^^^^^^

sord_examples/yard.rbi:4501: Type Elem declared by parent YARD::Parser::Ruby::AstNode must be re-declared in YARD::Parser::Ruby::ReferenceNode https://srb.help/5036
    4501 |      class ReferenceNode < AstNode
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    sord_examples/yard.rbi:4361: Elem declared in parent here
    4361 |      class AstNode < Array
                ^^^^^^^^^^^^^^^^^^^^^

Describe the solution you'd like The simplest solution would be to just define the necessary constants for each parent class that needs this (Array, Struct, etc.), but that's somewhat fragile. I'm not sure if there's a way for us to determine what Sorbet wants us to add when generating the rbi file?

I suppose these constants wouldn't change very often for core classes like this, so it may be fine to just handle it on a case-by-case basis in Sord.

Describe alternatives you've considered I'd prefer if Sorbet magically fixed this itself, but I don't think it can :(

AaronC81 commented 5 years ago

This is certainly a tricky one. I'm not too familiar with how type_member works, but my understanding is that, for an array, Elem should be set to the type of each element in the array. Is there any way this could be determined through YARD, or would we just use T.untyped?

connorshea commented 5 years ago

Probably just T.untyped.

DarkDimius commented 5 years ago

T.untyped should work as a stop-gap solution here. Elem = type_member(fixed: T.untyped)