8000 Inconsistent type assignment with different pattern matching syntax for nested object · Issue #8912 · sorbet/sorbet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Inconsistent type assignment with different pattern matching syntax for nested object #8912

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

Open
AndrewSwerlick opened this issue May 23, 2025 · 0 comments
Labels
bug Something isn't working unconfirmed This issue has not yet been confirmed by the Sorbet team

Comments

@AndrewSwerlick
Copy link

Input

→ View on sorbet.run

# typed: true
class Box
  def initialize(value)
    @value = value
  end

  def deconstruct
    [@value]
  end
end


class A
  extend T::Sig
  sig{ params(foo: T.any(Integer, String)).returns(Integer) }
  def bar(foo)
    case foo
    in Box[Integer => value]
      T.reveal_type(value)
    in [[Integer => value]]
      T.reveal_type(value)
    end
  end
end

Observed output

editor.rb:19: Revealed type: NilClass https://srb.help/7014
    19 |      T.reveal_type(value)
              ^^^^^^^^^^^^^^^^^^^^
  Got NilClass originating from:
    editor.rb:16: Possibly uninitialized (NilClass) in:
    16 |  def bar(foo)
          ^^^^^^^^^^^^

editor.rb:21: Revealed type: T.untyped https://srb.help/7014
    21 |      T.reveal_type(value)
              ^^^^^^^^^^^^^^^^^^^^
  Got T.untyped originating from:
    editor.rb:20:
    20 |    in [[Integer => value]]
                            ^^^^^
Errors: 2

Expected behavior

In the above example, I would have expected both calls to T.reveal_type(value) to result in T.untyped However what we see instead is that when using the combination of a value pattern + an array pattern, the value gets type NilClass. When we use a nested array pattern the value is assigned T.untyped

In both cases value should get assigned the type T.untyped

@AndrewSwerlick AndrewSwerlick added bug Something isn't working unconfirmed This issue has not yet been confirmed by the Sorbet team labels May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unconfirmed This issue has not yet been confirmed by the Sorbet team
Projects
None yet
Development

No branches or pull requests

1 participant
0