Skip to content

Hash#key? rejects interned parameter in Steep 2.0.0 (worked in 1.10.0) #2227

Description

@bolshakov

Steep 2.0.0 incorrectly reports a type error when passing an interned value to Hash#key?, even though interned should be compatible with my type signature. This worked correctly in Steep 1.10.0.

Environment

  • Steep version: 2.0.0
  • RBS version: 4.0.2
  • Ruby version: 3.2.4, 4.0.2

Ruby:

class Example
  def initialize
    @shas = {}
  end

  def script_sha(script_name)
    if shas.key?(script_name)  # Type error here
      shas[script_name]
    end
  end
end

RBS:

class Example
  attr_reader shas: Hash[interned, String]

  def script_sha: (interned script_name) -> String?
end

Error Message

lib/example.rb:4:17: [error] Cannot pass a value of type `::interned` as an argument of type `::Hash::_Key`
│   ::interned <: ::Hash::_Key
│     (::Symbol | ::string) <: ::Hash::_Key
│       ::string <: ::Hash::_Key
│         (::String | ::_ToStr) <: ::Hash::_Key
│           ::_ToStr <: ::Hash::_Key
│
│ Diagnostic ID: Ruby::ArgumentTypeMismatch
│
└     if shas.key?(script_name)
                 ~~~~~~~~~~~

This code type-checked successfully in Steep 1.10.0. interned is a built-in RBS type alias defined as Symbol | String

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions