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

Conditional ivar assignment in initialize should check default value #3669

Closed
JacobUb opened this issue Dec 11, 2016 · 0 comments
Closed

Conditional ivar assignment in initialize should check default value #3669

JacobUb opened this issue Dec 11, 2016 · 0 comments

Comments

@JacobUb
Copy link
Contributor

JacobUb commented Dec 11, 2016

class Foo
  @bar = 0

  def initialize(string)
    if string.size > 0
      @bar = string.size
    end
  end
end

Foo.new("hello") # => instance variable '@bar' of Foo must be Int32, not Nil

I think it should use the default value that it was already given. It's what it does if initialize doesn't mention @bar at all.

@asterite asterite added this to the 0.20.2 milestone Dec 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants