diff options
author | Mike Dalessio <[email protected]> | 2024-12-02 17:07:24 -0500 |
---|---|---|
committer | git <[email protected]> | 2024-12-02 22:07:31 +0000 |
commit | 4cce246d86d8ce16f13cfbbec465e0279d060f7f (patch) | |
tree | 53d5677f8dc7dd155ff6a91d1c22c07d4f29f986 /lib | |
parent | d588a1c880c5aadb3a802358df73b0c6e1fcf1a1 (diff) |
[ruby/rdoc] ClassModule#superclass= accepts a ClassModule as an
argument
(https://github.com/ruby/rdoc/pull/1222)
It is necessary for ClassModule's instance variable @superclass to
always be a String (or nil) so that the class can be saved with
`#marshal_dump` and loaded with `#marshal_load`.
However, there's no type checking being done, which allows a bug like
the one reported in #1221 (which was introduced in #1217) that sets
superclass to a ClassModule. That bug requires:
- setting a superclass to a NormalClass
- marshal_save
- marshal_load (which raises an exception)
With this change, passing a ClassModule to ClassModule#superclass= is
explicitly allowed by saving the full name of the ClassModule in the
@superclass instance variable.
https://github.com/ruby/rdoc/commit/9ced6d534c
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rdoc/code_object/class_module.rb | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/rdoc/code_object/class_module.rb b/lib/rdoc/code_object/class_module.rb index 9230c46983..33e71ab3f3 100644 --- a/lib/rdoc/code_object/class_module.rb +++ b/lib/rdoc/code_object/class_module.rb @@ -705,10 +705,23 @@ class RDoc::ClassModule < RDoc::Context ## # Set the superclass of this class to +superclass+ + # + # where +superclass+ is one of: + # + # - +nil+ + # - a String containing the full name of the superclass + # - the RDoc::ClassModule representing the superclass def superclass=(superclass) raise NoMethodError, "#{full_name} is a module" if module? - @superclass = superclass + case superclass + when RDoc::ClassModule + @superclass = superclass.full_name + when nil, String + @superclass = superclass + else + raise TypeError, "superclass must be a String or RDoc::ClassModule, not #{superclass.class}" + end end ## |