ruby / rbs

Type Signature for Ruby
Other
1.91k stars 201 forks source link

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

Open HoneyryderChuck opened 2 weeks ago

HoneyryderChuck commented 2 weeks ago
# 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
soutaro commented 2 weeks ago

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

スクリーンショット 2024-06-13 17 38 01
HoneyryderChuck commented 2 weeks ago
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.

soutaro commented 2 weeks ago

💡 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.