semantic icon indicating copy to clipboard operation
semantic copied to clipboard

Bug when sorting an enumerable that includes nil

Open perlun opened this issue 9 years ago • 3 comments

This is what I get:

rake aborted!
TypeError: can't dup NilClass
/Library/Ruby/Gems/2.0.0/gems/semantic-1.4.1/lib/semantic/version.rb:52:in `dup'
/Library/Ruby/Gems/2.0.0/gems/semantic-1.4.1/lib/semantic/version.rb:52:in `<=>'
/Users/plundberg/git/mforms-addons-platform/Rakefile:25:in `sort'

Too lazy/busy to make a failing spec for it at the moment, but it should be trivial. IMHO, comparing "anything" to nil should always return 1, i.e. "anything" is higher than nil.

perlun avatar Apr 28 '15 10:04 perlun

Hey @perlun I know this is a million years late but is this still an issue? If so could I bother you for an example?

jlindsey avatar Nov 08 '16 16:11 jlindsey

This is still an issue:

nil == Semantic::Version.new('1.0.0')
# false

Semantic::Version.new('1.0.0') == nil
# TypeError: can't dup NilClass   // v1.4.1
# NoMethodError: undefined method `major' for nil:NilClass   // v1.5.0

Semantic::Version.new('1.0.0') > nil
# TypeError: can't dup NilClass   // v1.4.1
# NoMethodError: undefined method `major' for nil:NilClass   // v1.5.0

Caused by the spaceship (<=>) operator not handling nil case

[updated] the errors are not the same with the version 1.4.x and 1.5.0

vmeyet avatar Nov 14 '16 12:11 vmeyet

Thanks for the update @vmeyet. I'll take a look at this today and hopefully cut a new version with the fix.

jlindsey avatar Nov 14 '16 15:11 jlindsey