[#54738] [ruby-trunk - Bug #8358][Open] TestSprintf#test_float test failuer on mingw32 — "phasis68 (Heesob Park)" <phasis@...>

36 messages 2013/05/02

[#54749] [ruby-trunk - Feature #8361][Open] Alternative syntax for block parameter — "alexeymuranov (Alexey Muranov)" <redmine@...>

12 messages 2013/05/02

[#54798] [ruby-trunk - Bug #8370][Open] Constants MAX_MULTIPART_LENGTH in cgi\core.rb — "xibbar (Takeyuki FUJIOKA)" <xibbar@...>

17 messages 2013/05/05

[#54850] [ruby-trunk - Feature #8377][Open] Deprecate :: for method calls in 2.1 — "charliesome (Charlie Somerville)" <charliesome@...>

27 messages 2013/05/07

[#54881] [ruby-trunk - Bug #8384][Open] Cannot build ruby against OpenSSL build with "no-ec2m" — "vo.x (Vit Ondruch)" <v.ondruch@...>

16 messages 2013/05/09

[#54921] [ruby-trunk - Bug #8393][Open] A class who's parent class is in a module can go wrong if files are required in the wrong order — "eLobato (Daniel Lobato Garcia)" <elobatocs@...>

15 messages 2013/05/12

[#54939] [ruby-trunk - Bug #8399][Open] Remove usage of RARRAY_PTR in C extensions when not needed — "dbussink (Dirkjan Bussink)" <d.bussink@...>

32 messages 2013/05/12

[#55053] [ruby-trunk - Feature #8426][Open] Implement class hierarchy method caching — "charliesome (Charlie Somerville)" <charliesome@...>

21 messages 2013/05/19

[#55096] [ruby-trunk - Feature #8430][Open] Rational number literal — "mrkn (Kenta Murata)" <muraken@...>

28 messages 2013/05/21

[#55197] [ruby-trunk - Feature #8461][Open] Easy way to disable certificate checking in XMLRPC::Client — "herwinw (Herwin Weststrate)" <herwin@...>

11 messages 2013/05/29

[ruby-core:55142] [ruby-trunk - Feature #8393] A class who's parent class is in a module can go wrong if files are required in the wrong order

From: "rkh (Konstantin Haase)" <me@...>
Date: 2013-05-23 08:40:20 UTC
List: ruby-core #55142
Issue #8393 has been updated by rkh (Konstantin Haase).


eLobato (Daniel Lobato Garcia) wrote:
> This error showed up in a Rails app, on my code I had two different files (ProxyAPI::Resource and ProxyAPI::BMC < Resource), and somehow there was a separated Resource class defined by a loaded gem. Then ProxyAPI::BMC was inheriting from that one instead of ProxyAPI::Resource, which caused problems. 
> 
> The warning could happen at initialization, but if a constant inside the module is added, IMO it should be inherited. Nonetheless I don't know too much about constant lookup at the moment, could you point me to the relevant parts of the code base or something like that? 
> 
> My only concern with the warning showing up just when the class is defined, is that maybe it will be hard to notice, but it's surely better than no warning at all.

Warnings would need to be really really smart or a lot of libraries will start printing warnings (for instance, rack defines Rack::File). I have to say, the whole issue would not have occurred if you had either required bark from dog (which is what require is for) or, if you want to use Rails' autoloading magic, used the qualified constant name (ie inherit from Bark::Animal).


----------------------------------------
Feature #8393: A class who's parent class is in a module can go wrong if files are required in the wrong order
https://bugs.ruby-lang.org/issues/8393#change-39507

Author: eLobato (Daniel Lobato Garcia)
Status: Feedback
Priority: Normal
Assignee: 
Category: 
Target version: 


Hi,

I have found that inheritance is not done properly in a certain case. Let's say we have the following files:

--------------
animal.rb -

class Animal
  def bark
    puts 'fuck.'
  end
end
 

dog.rb -

module Bark
  class Dog < Animal
  end
end


bark.rb - 

module Bark
  class Animal
    def bark
      puts 'woof'
    end
  end
end
------------

If these files are required in that order (or any order where Bark::Animal is not required before Animal), Bark::Dog.new.bark will output "fuck.", showing the inheritance was done wrong, because in the case that there are two classes from which it can inherit (Animal and Bark::Animal), it should inherit from the class inside its module (Bark).

A workaround for this is defining Dog as Dog < Bark::Animal, that forces Dog to use the correct Animal class. 

I found this on the latest 1.8.7, 1.9.2, 1.9.3 and 2.0.0dev, both using rvm and without using it. I could not find information about this on the issue tracker or on Google.

In my opinion a way to fix this is to check when a file is required if any of our current files could inherit from something in a module of the file that is imported, but that looks like it can be complicated with nested modules, etc.. so I'm all ears for better design decisions. 

I would like to fix this myself as my first Ruby core contribution, but I was unsure if this is an actual bug. To me it looks like this behavior is totally unexpected, let me know if anything is wrong here.

Thanks!



-- 
http://bugs.ruby-lang.org/

In This Thread