From: "Eregon (Benoit Daloze)" Date: 2022-06-17T10:45:24+00:00 Subject: [ruby-core:108981] [Ruby master Bug#18832] Suspicious superclass mismatch Issue #18832 has been updated by Eregon (Benoit Daloze). Yes, I think that's a great example why we should fix this. Anyone should still be able to define a `Comment` (defined as a constant of `Object`) class with just `class Comment` at the top-level, even if with `REXML::Comment` + `include REXML`. BTW, I thought `class Object::Comment < String; end` might be a workaround but it does not (as Jeremy found out as well above): ```ruby $ ruby -v -rrexml -e 'include REXML; class Object::Comment < String; end' ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-linux] -e:1:in `
': superclass mismatch for class Comment (TypeError) ``` This is also very surprising (the intention is to define `Object::Comment` with a superclass of `Object`): ```ruby $ ruby -v -rrexml -e 'include REXML; class Comment; end; p Comment.ancestors' ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-linux] [REXML::Comment, Comparable, REXML::Child, REXML::Node, Object, REXML, PP::ObjectMixin, Kernel, BasicObject] ``` ---------------------------------------- Bug #18832: Suspicious superclass mismatch https://bugs.ruby-lang.org/issues/18832#change-98086 * Author: fxn (Xavier Noria) * Status: Open * Priority: Normal * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- The following code: ```ruby module M class C end end include M p Object.const_defined?(:C, false) class C < String # (1) end ``` prints `false`, as expected, but then raises `superclass mismatch for class C (TypeError)` at (1). I believe this is a bug, because `Object` itself does not have a `C` constant, so (1) should just work, and the superclasse of `M::C` should be irrelevant. -- https://bugs.ruby-lang.org/ Unsubscribe: