steep icon indicating copy to clipboard operation
steep copied to clipboard

should remove nil on "if var"

Open HoneyryderChuck opened this issue 4 years ago • 4 comments

Having the following pattern code:

# @key defined as Integer?
# find: (Integer) -> String
key = find(@key) if @key

Steep fails to check the code above, with something like "Cannot pass a value of type Integer | nil as an argument of type Integer", however, it passes if I do ... unless @key.nil?. The same logic should be applied to the code above, which is a common ruby pattern.

HoneyryderChuck avatar Dec 31 '21 15:12 HoneyryderChuck

This is because instance variable can be changed from different thread. I know this is not useful for most cases. Planning to relax the limitation.

soutaro avatar Jun 11 '22 06:06 soutaro

This cannot be done in Steep 1.1. It requires something similar to live-variable analysis to detect if the assignment is executed before any reference of the variable.

soutaro avatar Jul 20 '22 15:07 soutaro

@soutaro is there any way around this without changing the signature of the method? I'm also fine with somehow ignoring it and silencing the error if possible

antstorm avatar Oct 26 '22 16:10 antstorm