steep icon indicating copy to clipboard operation
steep copied to clipboard

steep ignores assignments to variables through local scopes

Open p-datadog opened this issue 5 months ago • 0 comments

When a variable is overwritten from a block scope, steep ignores the overwrite. Example:

value = nil

loop do
  value = 1
  break
end

value + 2

puts value

Result:

% be steep check
# Type checking files:

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

test.rb:8:6: [error] Type `nil` does not have method `+`
│ Diagnostic ID: Ruby::NoMethod
│
└ value + 2
        ~

Detected 1 problem from 1 file

The above example is valid Ruby code. Is there a way to not have steep generate an error on it?

A more real-world usage example of the same pattern is Benchmark.realtime:

value = nil
time = Benchmark.realtime do
  value = ...
end

p-datadog avatar Sep 24 '24 20:09 p-datadog