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

False positive of Instance Variable Assumption with Struct initialize overload #1492

Closed
ryym opened this issue Oct 1, 2019 · 1 comment · Fixed by #1737
Closed

False positive of Instance Variable Assumption with Struct initialize overload #1492

ryym opened this issue Oct 1, 2019 · 1 comment · Fixed by #1737
Labels

Comments

@ryym
Copy link

ryym commented Oct 1, 2019

Hi, I found an issue about Instance Variable Assumption that occurs when a class have a Struct with its own initialize method in its block.

Example code:

class Foo
  Bar = Struct.new(:a) do
    def initialize(a)
      super
      p 'bar created'
    end
  end

  def initialize
    @foo = :foo
  end

  def foo?
    @foo == :foo
  end
end

When I run reek against this file, Reek reports a warning of Instance Variable Assumption, even though @foo in Foo class is initialized correctly.

[1]:InstanceVariableAssumption: Foo assumes too much for instance variable '@foo' [https://github.com/troessner/reek/blob/v5.4.0/docs/Instance-Variable-Assumption.md]

It looks like the cause is Bar which has a block containing an initialize method.
I confirmed that Reek did not warn if:

  • Bar does not have an initialize method.
  • Bar is defined by normal class syntax (class Bar ... end).
  • Bar is defined after the initialize method of Foo.

Similar issue: #1137

@troessner
Copy link
Owner

Oh, good catch! Yes, that definitely looks like a bug on our side. Thank you for that detailed report, we will look into this (not sure when though).

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

Successfully merging a pull request may close this issue.

2 participants