Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#delete compatibility with from SortedSet from Stdlib #8

Open
themilkman opened this issue Nov 11, 2021 · 1 comment
Open

#delete compatibility with from SortedSet from Stdlib #8

themilkman opened this issue Nov 11, 2021 · 1 comment

Comments

@themilkman
Copy link

Hi,

I run in the following issue using SortedSet as drop in replacement:

3.0.2 :001 > str = "foo";ss = SortedSet.new; ss << str; hsh = { enabled: ss}; hsh[:enabled].delete(nil)
/home/me/.rvm/gems/ruby-3.0.2/gems/set-1.0.2/lib/set.rb:540:in `delete': comparison of NilClass with String failed (ArgumentError)
  from /home/me/.rvm/gems/ruby-3.0.2/gems/set-1.0.2/lib/set.rb:540:in `delete'
  from (irb):1:in `<main>'
  from /home/me/.rvm/rubies/ruby-3.0.2/lib/ruby/gems/3.0.0/gems/irb-1.3.5/exe/irb:11:in `<top (required)>'
  from /home/me/.rvm/rubies/ruby-3.0.2/bin/irb:23:in `load'
  from /home/me/.rvm/rubies/ruby-3.0.2/bin/irb:23:in `<main>'

While with ruby 2.7.4:

2.7.4 :001 > str = "foo";ss = SortedSet.new; ss << str; hsh = { enabled: ss}; hsh[:enabled].delete(nil)
 => #<SortedSet: {"foo"}> 

If I debugged it correctly this is due to RBTree:

3.0.2 :002 >  rb = RBTree["", ""]; rb.delete(0)
(irb):4:in `delete': comparison of Integer with String failed (ArgumentError)
  from (irb):4:in `<main>'
  from /home/me/.rvm/rubies/ruby-3.0.2/lib/ruby/gems/3.0.0/gems/irb-1.3.5/exe/irb:11:in `<top (required)>'
  from /home/me/.rvm/rubies/ruby-3.0.2/bin/irb:23:in `load'
  from /home/me/.rvm/rubies/ruby-3.0.2/bin/irb:23:in `<main>'

Is this mismatch in functionality generally accepted or is it smth that should get solved in sorted_set?

Thanks and cheers!

@jaynetics
Copy link

IMHO this error should not leak from a dependency and SortedSet should be usable as a drop-in for Set (Liskov substitution)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants