steep
steep copied to clipboard
Type check is not done when using rightward assignment to destructure the return value of a method
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
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)