soutaro / steep

Static type checker for Ruby
MIT License
1.34k stars 88 forks source link

Support splatting non-`_ToA`s #926

Open ParadoxV5 opened 9 months ago

ParadoxV5 commented 9 months ago

(all_error diagnostic)

$ cat ruby.rb
def q(o) = p(o)

q(*1)
p(*2)
$ ruby ruby.rb
1
2
$ cat rbs.rbs
class Object
  def q: (untyped) -> void
end
$ steep check
# Type checking files:

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

ruby.rb:3:2: [error] Unexpected positional argument
│ Diagnostic ID: Ruby::UnexpectedPositionalArgument
│
└ q(*1)
    ~~

ruby.rb:4:2: [error] Unsupported splat node occurrence
│ Diagnostic ID: Ruby::UnsupportedSyntax
│
└ p(*2)
    ~~

ruby.rb:4:0: [error] Cannot find compatible overloading of method `p` of type `::Object`
│ Method types:
│   def p: [T < ::_Inspect] (T) -> T
│        | (::_Inspect, ::_Inspect, *::_Inspect) -> ::Array[::_Inspect]
│        | () -> nil
│
│ Diagnostic ID: Ruby::UnresolvedOverloading
│
└ p(*2)
  ~~~~~

Detected 3 problems from 1 file
Forthoney commented 3 months ago

I disagree that steep should support this. This behavior is likely a byproduct of the implicit argument manipulation that happens when dealing with splats in function calls. I think either explicitly raising an error or at the least raising a warning when such code is encountered would be the right way to go. With that said, I think UnsupportedSyntax is not the correct error to raise, since it is supported syntax.