Commit cffd0daf
cffd0dafed3aMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified
Description
Treat module/class constants as first-class Module objects
Reflection methods on a module or class constant misbehaved because the sp_Class value wasn't carried as a proper Module/Class object:
-
Module#name / #to_s / #inspect on a nested constant rendered the C-mangled
Foo_Barinstead ofFoo::Bar. The sp_class_names[] table now stores the Ruby-visible name via cls_name_to_ruby, which also learns to unmangle class-nested (not just module-nested) prefixes, so a nested exception class like AeNetworkConnectionException::ConnectionNotEstablished reports its::name too. -
.classon a module/class constant errored or returned Integer. It now returns Module or Class, chosen at runtime by sp_class_is_module (a threshold compare on the unified cls_id space), so dynamic Class-typed values work as well as static constants. The analyzer types<class-value>.classasclass, and a nested ConstantPathNode module reference (Outer::Inner) now types asclassinstead of falling through to int. -
is_a?/kind_of?/instance_of?(Module|Class|Object|...) returned false for a module/class value. They now answer correctly: is_a?(Module) is true for any class value, is_a?(Class) only for classes, instance_of? distinguishes the two. A non-literal class argument still falls through rather than collapsing to false.
Fixes #1044 Fixes #1047 Fixes #1049
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- cffd0dafed3a
- Parent
- 46bf64108329
spinel_analyze.rbmodifiedView file
# class constant in value position. return "class" end # nested module constant in value position (`Outer::Inner` # where Inner is a module) — same sp_Class representation as # the ConstantReadNode case above. if module_name_exists(cpname) == 1 return "class" end if is_builtin_class_const_name(cpname) == 1 return "class" end end parent = @nd_receiver[nid] if parent >= 0 if bt_pc == "poly" || bt_pc == "poly?" return "class" end # `.class` on a class/module value -> Class or Module, itself a # class value. if bt_pc == "class" return "class" end end end # `<obj>.class.<cmeth>` chained dispatch. When thespinel_codegen.rbmodifiedView file
Loading diff…
test/module_class_reflection.rbaddedView file
Loading diff…
test/module_class_reflection.rb.expectedaddedView file
Loading diff…