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

Type check is not done when using rightward assignment to destructure the return value of a method #1080

Open
rozner opened this issue Mar 20, 2024 · 1 comment

Comments

@rozner
Copy link

rozner commented Mar 20, 2024

In case a method returns with a well defined hash then type checking works fine when you reference the values directly in the hash as seen with methods ok_direct and ok_indirect. However when using rightwards assignment no errors are given as seen with the rightward method.

Environment

$ ruby --version
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
$ steep --version
1.6.0
$ rbs --version
rbs 3.4.4

How to reproduce

# test.rb
module A
  def self.init
    { num: 1, str: 'str' }
  end

  def ok_direct
    init[:str].sqrt
  end

  def ok_indirect
    h = init
    num = h[:num]
    str = h[:str]

    str.sqrt
  end

  def rightward
    init => {num:, str:}
    str.sqrt
  end
end
# test.rbs
module A
  def init: () -> { num: Integer, str: String }
  def ok: () -> void
  def nok: () -> void
end
$ steep check

# Type checking files:

..............................................................F......................

lib/test.rb:7:15: [error] Type `::String` does not have method `sqrt`
│ Diagnostic ID: Ruby::NoMethod
│
└     init[:str].sqrt
                 ~~~~

lib/test.rb:15:8: [error] Type `::String` does not have method `sqrt`
│ Diagnostic ID: Ruby::NoMethod
│
└     str.sqrt
          ~~~~

Detected 2 problems from 1 file
@ksss
Copy link
Contributor

ksss commented Mar 31, 2024

Pattern matching is not yet supported in Steep.
I believe the following is reported in the LSP.

Syntax `match_pattern` is not supported in Steep(Ruby::UnsupportedSyntax)

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

No branches or pull requests

2 participants