Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Parser incorrectly handles nested sclass definitions #22

Closed
pithyless opened this Issue · 1 comment

2 participants

@pithyless

Came across an issue while using flog to parse sinatra's code base. Specifically, the culprit is: https://github.com/sinatra/sinatra/blob/62b6e1f871319089a4b09e172a8add2dbae44bd8/lib/sinatra/base.rb#L1326-1332

Here's an example to reproduce the issue.

Flog correctly finds Foo's instance method and class method with the same name. On the other hand, flog interprets everything in Bar after define_singleton to be instance methods and ends up merging the two methods into one score.

class Foo
  def foo
    42
  end

  class << self
    def foo
      42
    end
  end
end

class Bar
  def bar
    42
  end

  class << self
    def define_singleton
      (class << self; self; end).class_eval do
        "waaaaa?!?!"
      end
    end

    def bar
      42
    end
  end
end
› flog -a test.rb
    29.4: flog total
     4.9: flog/method average

    17.1: Bar::define_singleton            test.rb:19
     5.5: Foo#none
     5.5: Bar#none
     0.7: Bar#bar                          test.rb:25
     0.4: Foo::foo                         test.rb:7
     0.3: Foo#foo                          test.rb:2

If I understand correctly, the issue is that flog tracks the sclass scope as a boolean in @sclass.

Maybe it should be switched to an array that could keep track of a stack of self scopes? I can try to come up with a patch if you agree this is the right direction.

@zenspider zenspider was assigned
@zenspider
Owner

Thanks!

@zenspider zenspider closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.