steep icon indicating copy to clipboard operation
steep copied to clipboard

steep misunderstands string and array slice types

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

Correct me if I'm wrong but I don't think a string slice that begins at the beginning of a string can ever be nil.

For example steep complains of the following code:

a=''
a[0..0]+'x'

Thusly:

test.rb:2:7: [error] Type `(::String | nil)` does not have method `+`
│ Diagnostic ID: Ruby::NoMethod
│
└ a[0..0]+'x'
         ~

nil is not a possible type for a[0..0] when a is a String.

Same problem with arrays:

a=[]
a[0..]+[]
test.rb:2:6: [error] Type `(::Array[untyped] | nil)` does not have method `+`
│ Diagnostic ID: Ruby::NoMethod
│
└ a[0..]+[]
        ~

p-datadog avatar Sep 11 '24 17:09 p-datadog