defunkt / tomdoc

A TomDoc Ruby library.
http://tomdoc.org/
MIT License
114 stars 16 forks source link

undefined method `instance_methods' for nil:NilClass (NoMethodError) #5

Open millisami opened 14 years ago

millisami commented 14 years ago

I installed tomdoc and made a sample ruby file and executed the tomdoc, but it blows out with the following error:

ree-1.8.7-2010.02@tomdoc [~/tmp/tomdoc] ➔ tomdoc tomdoc-demo.rb 
/Users/millisami/.rvm/gems/ree-1.8.7-2010.02@tomdoc/gems/tomdoc-0.1.0/lib/tomdoc/source_parser.rb:89:in `process': undefined method `instance_methods' for nil:NilClass (NoMethodError)
    from /Users/millisami/.rvm/gems/ree-1.8.7-2010.02@tomdoc/gems/tomdoc-0.1.0/lib/tomdoc/source_parser.rb:51:in `parse'
    from /Users/millisami/.rvm/gems/ree-1.8.7-2010.02@tomdoc/gems/tomdoc-0.1.0/lib/tomdoc/source_parser.rb:10:in `parse'
    from /Users/millisami/.rvm/gems/ree-1.8.7-2010.02@tomdoc/gems/tomdoc-0.1.0/lib/tomdoc/generator.rb:29:in `generate'
    from /Users/millisami/.rvm/gems/ree-1.8.7-2010.02@tomdoc/gems/tomdoc-0.1.0/lib/tomdoc/cli.rb:101
    from /Users/millisami/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/optparse.rb:1318:in `call'
    from /Users/millisami/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/optparse.rb:1318:in `parse_in_order'
    from /Users/millisami/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/optparse.rb:606:in `search'
    from /Users/millisami/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/optparse.rb:1418:in `send'
    from /Users/millisami/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/optparse.rb:1418:in `visit'
    from /Users/millisami/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/optparse.rb:1417:in `reverse_each'
    from /Users/millisami/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/optparse.rb:1417:in `visit'
    from /Users/millisami/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/optparse.rb:1318:in `parse_in_order'
    from /Users/millisami/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/optparse.rb:1248:in `order!'
    from /Users/millisami/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/optparse.rb:1339:in `permute!'
    from /Users/millisami/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/optparse.rb:1360:in `parse!'
    from /Users/millisami/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/optparse.rb:1350:in `parse'
    from /Users/millisami/.rvm/gems/ree-1.8.7-2010.02@tomdoc/gems/tomdoc-0.1.0/lib/tomdoc/cli.rb:118:in `parse_options'
    from /Users/millisami/.rvm/gems/ree-1.8.7-2010.02@tomdoc/gems/tomdoc-0.1.0/lib/tomdoc/cli.rb:114:in `parse_options'
    from /Users/millisami/.rvm/gems/ree-1.8.7-2010.02@tomdoc/gems/tomdoc-0.1.0/lib/tomdoc/cli.rb:146
    from /Users/millisami/.rvm/gems/ree-1.8.7-2010.02@tomdoc/gems/tomdoc-0.1.0/bin/tomdoc:6
    from /Users/millisami/.rvm/gems/ree-1.8.7-2010.02@tomdoc/bin/tomdoc:19:in `load'
    from /Users/millisami/.rvm/gems/ree-1.8.7-2010.02@tomdoc/bin/tomdoc:19
trans commented 13 years ago

I was looking at the code for this. The method involved is:

    def process(ast, scope = nil)
      case Array(ast)[0]
      when :module, :class
        name = ast[1]
        new_scope = Scope.new(name, ast[2])

        if scope
          scope.scopes[name] = new_scope
        elsif @scopes[name]
          new_scope = @scopes[name]
        else
          @scopes[name] = new_scope
        end

        process(ast[3], new_scope)
      when :imethod
        ast.shift
        scope.instance_methods << Method.new(*ast)
      when :cmethod
        ast.shift
        scope.class_methods << Method.new(*ast)
      when Array
        ast.map { |a| process(a, scope) }
      end
    end

So the problem is that scope can, in certain cases, be nil. Unfortunately I don't know enough about what this method is accomplishing to be sure of a proper fix.

trans commented 13 years ago

Does this address the problem?

https://github.com/defunkt/tomdoc/blob/tomdoc.rb/lib/tomdoc/source_parser.rb#L89

I really wouldn't have expected this error. What does a nil scope mean? I'm guessing that a nil scope can only happen for toplevel? I mean how else could a nil scope be possible? Not sure what the proper reference for toplevel is in the @scopes hash, so this still needs to be fixed.

defunkt commented 13 years ago

@millisami Can you post your example file?

defunkt commented 13 years ago

Scratch that, I can reproduce :)

millisami commented 13 years ago

alright!

AndrewToon commented 1 year ago

Api test

AndrewToon commented 1 year ago

MWF5MTcyYS01YzQ5LTQ1MGMtODkzMy0yNTdlNGAeOTIyNmJfd2lucGxhY2Vob2xkAXR8AWIuc2l0AS9eb21tYW5kcy3=!