Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elem constant generation #93

Open
connorshea opened this issue Jul 20, 2019 · 3 comments
Open

Elem constant generation #93

connorshea opened this issue Jul 20, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@connorshea
Copy link
Contributor

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 :(

@connorshea connorshea added the enhancement New feature or request label Jul 20, 2019
@AaronC81
Copy link
Owner

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
Copy link
Contributor Author

Probably just T.untyped.

@DarkDimius
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants