Skip to content

Conversation

@tenderlove
Copy link
Member

It seems like we were trying to deprecate passing nil to Gem::Version.new. This breaks existing code, and I don't think there is a good reason to deprecate this usage.

I believe what we want to prevent is the following code:

Gem::Specification.new do |spec|
  spec.version = nil
  # suddenly the spec version is 0!
  p spec.version
end

This commit allows people to manually construct Gem::Version.new(nil), but when someone assigns nil as the Gem specification version, it sets the spec version to nil (making the specification invalid). People who manually construct Gem::Version objects and use nil should be allowed to do it, and Gem::Version.new(nil) == Gem::Version.new("0"), but people who assign nil in a gemspec will get an invalid gemspec.

I think deprecation started
here but there doesn't seem to be a reason to do it.

Fixes #9052

It seems like we were trying to deprecate passing `nil` to
Gem::Version.new.  This breaks existing code, and I don't think there is
a good reason to deprecate this usage.

I believe what we want to prevent is the following code:

```ruby
Gem::Specification.new do |spec|
  spec.version = nil
  # suddenly the spec version is 0!
  p spec.version
end
```

This commit allows people to manually construct `Gem::Version.new(nil)`,
but when someone assigns `nil` as the Gem specification version, it sets
the spec version to `nil` (making the specification invalid).  People
who manually construct `Gem::Version` objects and use nil should be
allowed to do it, and `Gem::Version.new(nil) == Gem::Version.new("0")`,
but people who assign `nil` in a gemspec will get an invalid gemspec.

I think deprecation started
[here](ruby#2203) but there doesn't
seem to be a reason to do it.

Fixes ruby#9052
@colby-swandale
Copy link
Member

#1767 also has a bit of context around this

@hsbt hsbt merged commit d00fb96 into ruby:master Nov 18, 2025
73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gem::Version.new deprecated accepting nil with a warning, but why?

3 participants