Skip to content

Self requiring file breaks inheritance hooks #3032

@Xanthus

Description

@Xanthus

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:

BaseClass
--->MiddleClass
------->Subclass1
------->Subclass2

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"
then run "ruby base_class.rb"

You should see output showing failure or success.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions