Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Self requiring file breaks inheritance hooks #3032
So first of all, this only happens when you do something lazy like I did and let a file require itself by iterating through a directory and requiring all files. The only reason I'm posting it is because the issue doesn't happen in MRI (tested on 2.2.1) but does in JRuby (1.7.19)
Basically in this contrived example you're supposed to end up with an inheritance tree like this:
MiddleClass has an inherited hook that registers its subclasses in a class instance variable. The file containing BaseClass loads the file containing MiddleClass. That then loads Subclass1, itself and then Subclass2. The result is that only Subclass2 gets registered by the inheritance hook.
This is a real edge case but I thought it would be worth reporting. I created a gist with a script to reproduce this by creating the files: https://gist.github.com/Xanthus/9494347f4345798113d9#file-generate_self_requiring_files-rb
run "ruby generate_self_requiring_files.rb"
You should see output showing failure or success.
This might be fixed on 1.7.20 already. This is because you are requiring the same file twice and it is getting registered twice in LOAD_PATH so first subclass probbably happens before it reloads the the mddleclass for a second time, then loads second subclass which then registers against new version. Sorry it is release day and I am too busy to verify this myself but try 1.7.20 and let us know.
This appears to have been fixed some time between 1.7.21 and now. Here's the
And here's master:
I did not test JRuby 1.7 in Ruby 1.8 mode because 1.8.7 does not make guarantees about loading the same file with different relative paths.
Calling this one fixed as of 1.7.24. Please verify @Xanthus, thank you!