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

superclass mismatch caused by Padrino::Reloader #1922

Closed
postmodern opened this issue May 29, 2015 · 7 comments
Closed

superclass mismatch caused by Padrino::Reloader #1922

postmodern opened this issue May 29, 2015 · 7 comments
Assignees
Labels

Comments

@postmodern
Copy link
Contributor

I was trying to run specific specs via bundle exec rspec spec/bars/ and got this error:

lib/test_app/foo/bar/baz.rb:8:in `': superclass mismatch for class Baz (TypeError)
    from test_app/lib/test_app/foo/bar/baz.rb:7:in `'
    from test_app/lib/test_app/foo/bar/baz.rb:6:in `'
    from test_app/lib/test_app/foo/bar/baz.rb:5:in `'
    from /home/hal/.gem/ruby/2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/reloader.rb:95:in `require'
    from /home/hal/.gem/ruby/2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/reloader.rb:95:in `block in safe_load'
    from /home/hal/.gem/ruby/2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/reloader.rb:304:in `with_silence'
    from /home/hal/.gem/ruby/2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/reloader.rb:95:in `safe_load'
    from /home/hal/.gem/ruby/2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/loader.rb:141:in `block in require_dependencies'
    from /home/hal/.gem/ruby/2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/loader.rb:139:in `each'
    from /home/hal/.gem/ruby/2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/loader.rb:139:in `require_dependencies'
    from /home/hal/.gem/ruby/2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/loader.rb:58:in `load!'
    from test_app/config/boot.rb:48:in `'
    from test_app/spec/spec_helper.rb:2:in `require'
    from test_app/spec/spec_helper.rb:2:in `'
    from test_app/spec/bars/baz_spec.rb:1:in `require'
    from test_app/spec/bars/baz_spec.rb:1:in `'
    from /home/hal/.gem/ruby/2.1.6/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1226:in `load'
    from /home/hal/.gem/ruby/2.1.6/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1226:in `block in load_spec_files'
    from /home/hal/.gem/ruby/2.1.6/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1224:in `each'
    from /home/hal/.gem/ruby/2.1.6/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1224:in `load_spec_files'
    from /home/hal/.gem/ruby/2.1.6/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:97:in `setup'
    from /home/hal/.gem/ruby/2.1.6/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:85:in `run'
    from /home/hal/.gem/ruby/2.1.6/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:70:in `run'
    from /home/hal/.gem/ruby/2.1.6/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:38:in `invoke'
    from /home/hal/.gem/ruby/2.1.6/gems/rspec-core-3.2.3/exe/rspec:4:in `'
    from /home/hal/.gem/ruby/2.1.6/bin/rspec:23:in `load'
    from /home/hal/.gem/ruby/2.1.6/bin/rspec:23:in `'

The contents of lib/foo/bar/baz.rb is roughly:

require 'foo/bar/base'

require 'baz'

module Foo
  module Bar
    class Baz < Base
      # ...
    end
  end
end

The require 'baz' loads another top-level Baz module unrelated to Foo::Bar::Baz. Adding p Baz right before the class Baz < Base shows that Padrino is loading the file twice.

bundle exec rspec spec/bars/
Baz
Foo::Bar::Baz
lib/foo/bar/baz.rb:9:in `': superclass mismatch for class Baz (TypeError)
@namusyaka
Copy link
Contributor

@postmodern Could you provide a minimal sample project ?

@ueno1969
Copy link

A similar error occurs in reloading.

project:
https://github.com/ueno1969/PadrinoSuperClassError

  1. start server

    padrino s    
    
  2. In other window

$ touch lib/woo.rb
$ curl "http://localhost:3000/"
TypeError: superclass mismatch for class Woo
        /home/k-ueno/project/TEST/sample_project/lib/woo.rb:7:in `<top (required)>'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/reloader.rb:95:in `require'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/reloader.rb:95:in `block in safe_load'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/reloader.rb:304:in `with_silence'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/reloader.rb:95:in `safe_load'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/reloader.rb:178:in `reload_regular'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/reloader.rb:51:in `block in reload!'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/reloader.rb:214:in `block in rotation'
        /home/k-ueno/.rvm/rubies/ruby-2.1.6/lib/ruby/2.1.0/set.rb:263:in `each_key'
        /home/k-ueno/.rvm/rubies/ruby-2.1.6/lib/ruby/2.1.0/set.rb:263:in `each'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/reloader.rb:211:in `rotation'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/reloader.rb:49:in `reload!'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/loader.rb:86:in `reload!'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/reloader/rack.rb:19:in `block in call'
        <internal:prelude>:12:in `block in exclusive'
        <internal:prelude>:11:in `synchronize'
        <internal:prelude>:11:in `exclusive'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/reloader/rack.rb:19:in `call'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/logger.rb:420:in `call'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/sinatra-1.4.6/lib/sinatra/show_exceptions.rb:21:in `call'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/rack-1.5.5/lib/rack/session/abstract/id.rb:225:in `context'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/rack-1.5.5/lib/rack/session/abstract/id.rb:220:in `call'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/sinatra-1.4.6/lib/sinatra/base.rb:2021:in `call'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/sinatra-1.4.6/lib/sinatra/base.rb:1486:in `block in call'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/sinatra-1.4.6/lib/sinatra/base.rb:1795:in `synchronize'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/sinatra-1.4.6/lib/sinatra/base.rb:1486:in `call'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/router.rb:84:in `block in call'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/router.rb:75:in `each'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/padrino-core-0.12.5/lib/padrino-core/router.rb:75:in `call'
        /home/k-ueno/.rvm/gems/ruby-2.1.6/gems/rack-1.5.5/lib/rack/handler/webrick.rb:60:in `service'
        /home/k-ueno/.rvm/rubies/ruby-2.1.6/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
        /home/k-ueno/.rvm/rubies/ruby-2.1.6/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
        /home/k-ueno/.rvm/rubies/ruby-2.1.6/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'%     

Server's log is

 $ padrino s
=> Padrino/0.12.5 has taken the stage development at http://127.0.0.1:3000
[2015-07-15 12:10:24] INFO  WEBrick 1.3.1
[2015-07-15 12:10:24] INFO  ruby 2.1.6 (2015-04-13) [x86_64-linux]
[2015-07-15 12:10:24] INFO  WEBrick::HTTPServer#start: pid=1405 port=3000
  ERROR -  TypeError - superclass mismatch for class Woo:
 /home/k-ueno/project/TEST/sample_project/lib/woo.rb:7:in `<top (required)>'
  ERROR -  Failed to load /home/k-ueno/project/TEST/sample_project/lib/woo.rb; removing partially defined constants
  • lib/woo.rb is
class Boo
  def self.class_method
    "BooClass"
  end
end

class Woo < Boo
end

If Boo's method is instance method or defining self.class_method in Woo class, no error occured.

@ujifgc ujifgc self-assigned this Jul 27, 2015
@ujifgc
Copy link
Member

ujifgc commented Jul 28, 2015

@ueno1969 thank you for your sample project, it helped a lot. Your problem is now fixed and tested on 0.12 and master branches by commits 0d63a31 and 544c856. Hopefully we can push 0.12.6 as a bug fix release soon.

@ueno1969
Copy link

Thank you so match !

@ujifgc
Copy link
Member

ujifgc commented Jul 29, 2015

Please keep in mind that the exact issue when a class without instance or class methods inherits from another class is still not resolved, so I'm keeping this issue open.

@ueno1969
Copy link

Noted with thanks.

Test result:

  • commit:"544c85648f8c847b6fe37a282adcc8dee141f34e"
    • same error ' TypeError - superclass mismatch for class Woo:' occured.
  • commit:"0d63a31cc1a78e2909275af513f65195c41a78a4"
    • No error.

@nesquena nesquena modified the milestone: 0.13.1 Oct 12, 2015
@ujifgc ujifgc modified the milestone: 0.13.1 Dec 12, 2015
@ujifgc
Copy link
Member

ujifgc commented Apr 28, 2016

Closing as lacking feedback and probably fixed.

@ujifgc ujifgc closed this as completed Apr 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants