rbs icon indicating copy to clipboard operation
rbs copied to clipboard

More details `Set.new`

Open ksss opened this issue 1 year ago • 2 comments

Since the implementation of Set is Hash, the key must have a hash method.

$ ruby -e 'Set.new([BasicObject.new])'
/Users/ksss/.rbenv/versions/3.3.0/lib/ruby/3.3.0/set.rb:509:in `add': undefined method `hash' for an instance of BasicObject (NoMethodError)

    @hash[o] = true
         ^^^^^

The type argument A for Set should strictly be A < Hash::_Key. However, making this change would break compatibility, so it cannot be done. In practice, using BasicObject is rare, so there is no need to make this change.

ksss avatar Apr 11 '24 01:04 ksss

@ksss

The type argument A for Set should strictly be A < Hash::_Key. However, making this change would break compatibility, so it cannot be done.

I'm fan of making the type parameter bounded, A < Hash::_Key. Did you see any specific compatibility problem with it?

soutaro avatar Apr 15 '24 03:04 soutaro

For Set only json has been found, but I have the following concern.

  • Only ruby/rbs and ruby/gem_rbs_collection were checked, and I am not sure if they are also completely absent in the sig directory distributed in the rubygems.
  • The same issue exists with Hash, which is used in activesupport.

ksss avatar Apr 15 '24 06:04 ksss

This PR has resolved by https://github.com/ruby/rbs/pull/1810

ksss avatar May 29 '24 02:05 ksss