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

Sorbet error suggests using the type that is being used #7586

Open
dduugg opened this issue Jan 10, 2024 · 0 comments
Open

Sorbet error suggests using the type that is being used #7586

dduugg opened this issue Jan 10, 2024 · 0 comments
Labels
bug Something isn't working
Milestone

Comments

@dduugg
Copy link
Contributor

dduugg commented Jan 10, 2024

Input

→ View on sorbet.run

# typed: true

class Hash
  extend T::Sig
  sig { returns(T.self_type) }
  def compact_blank
    reject { |_k, v| v } # would be v.blank?
  end
end

Observed output

editor.rb:7: Expected T::Hash[Hash::K, Hash::V] but found T::Hash[Hash::K, Hash::V] for method result type https://srb.help/7005
     7 |    reject { |_k, v| v } # would be v.blank?
            ^^^^^^^^^^^^^^^^^^^^
  Expected T::Hash[Hash::K, Hash::V] for result type of method compact_blank:
    editor.rb:6:
     6 |  def compact_blank
          ^^^^^^^^^^^^^^^^^
  Got T::Hash[Hash::K, Hash::V] originating from:
    editor.rb:7:
     7 |    reject { |_k, v| v } # would be v.blank?
            ^^^^^^^^^^^^^^^^^^^^
Errors: 1

Expected behavior

Error message should not be of the form "Expected X but found X for method result type"


(I can get around it in this example with a return type of T::Hash[K, V], but that has issues in the production code, and I'd prefer to be able to use T.self_type here.)

@dduugg dduugg added bug Something isn't working unconfirmed This issue has not yet been confirmed by the Sorbet team labels Jan 10, 2024
@jez jez removed the unconfirmed This issue has not yet been confirmed by the Sorbet team label Jan 10, 2024
@jez jez added this to the Generics milestone Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants