soutaro / steep

Static type checker for Ruby
MIT License
1.35k stars 84 forks source link

arr.delete(smth) should update type of arr if smth is specified in the signature #1064

Open HoneyryderChuck opened 6 months ago

HoneyryderChuck commented 6 months ago

Given an array arr typed as Array[Integer | :sym], given a call such as arr.delete(:sym), the type should be updated to Array[Integer], similar to the type narrowing performed by .nil? calls.

soutaro commented 6 months ago

Destructively updating type of something is not supported in Steep. It's a bit different from type narrowing with nil?, because it should be propagated to outer context, for example method caller context.

def foo(arr)
  arr.delete(:sym)
end

arr = [1, :sym]
foo arr
HoneyryderChuck commented 5 months ago

Just read that typescript will support smth of the kind in 5.5