rbs icon indicating copy to clipboard operation
rbs copied to clipboard

calling #each on obj typed with record yields |bot, bot| types

Open HoneyryderChuck opened this issue 1 year ago • 3 comments

# RBS
# type rec = {foo: String, bar: Integer }

# and having variable a typed as rec

a.each do |x, y|
# x and y appear as bot

I'm also assuming narrowing on key won't also work (but that's more of a feature request perhaps):

a.each do |x, y|

if x == :foo 
  # then y is a string

HoneyryderChuck avatar Jun 12 '24 10:06 HoneyryderChuck

Looks like it works with Steep 1.7.1. Can you give me some more detail to reproduce?

スクリーンショット 2024-06-13 17 38 01

soutaro avatar Jun 13 '24 08:06 soutaro

module A
  type context = {
    ?msg: Hash[interned, untyped],
    # identifiers
    ?identifiers: Hash[interned, untyped],
    # ....
  }

  def self?.hash_flat_merge: (context, context) -> context
}

Then "#each" declares them as bot in steep.

Captura de ecrã 2024-06-14, às 15 55 51

using latest rbs and steep.

HoneyryderChuck avatar Jun 14 '24 14:06 HoneyryderChuck

💡 Optional keys are not supported and simply ignored in Steep. The implementation in RBS was finished, but the Steep side slipped my mind. 🙇

@sampersand You may be interested in working for this.

soutaro avatar Jun 14 '24 18:06 soutaro