Inconsistencies when yielding multiple values
Coming from https://github.com/ruby/rbs/pull/733 , I also noticed an inconsistent behaviour, which generates steep errors, but it's probably due to RBS definitions.
Array#each and other yielders, yield the Elem to the block. However, these elements can be "spread", for example when having arrays of tuples:
[[1, 2], [2, 3]].each do |left, right|
# ...
This particular issue has been addressed by my fix for Hash, but can't really work for the "array of arrays" case. But probably my fix should be reverted, and instead, support for tuple yielding should be addd instead. WDYT?
I think this is an issue of Steep. (And I was thinking I have implemented the spread... Will take a look.)
Might be related, I'm not too sure, but unpacking a hash enumeration fails:
hsh.each.with_index do |(k, v), i|
Steep reports:
lib/datadog/appsec/waf.rb:285:33: [error] Unsupported block params pattern, probably masgn?
│ Diagnostic ID: Ruby::UnsupportedSyntax
│
└ hsh.each.with_index do |(k, v), i|
~~~~~~~~~~~
lib/datadog/appsec/waf.rb:285:10: [error] Cannot find compatible overloading of method `with_index` of type `::Enumerator[[untyped, untyped], ::Hash[untyped, untyped]]`
│ Method types:
│ def with_index: (?::Integer) { ([untyped, untyped], ::Integer) -> untyped } -> ::Hash[untyped, untyped]
│ | (?::Integer) -> ::Enumerator[[[untyped, untyped], ::Integer], ::Hash[untyped, untyped]]
│
│ Diagnostic ID: Ruby::UnresolvedOverloading
│
└ hsh.each.with_index do |(k, v), i|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
So I had to turn it into:
hsh.each.with_index do |e, i|
k, v = e[0], e[1] # for Steep, which doesn't handle |(k, v), i|
Spreading tuples onto block parameters is not supported by Steep as of 1.0.
I've been working for better multiple assignments, which will ship in Steep 1.1, and will work for block parameters next.