Commit 3d99fa63
3d99fa63c024Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
feat(codegen): emit <obj>.class as a class-name string literal
Spinel doesn't allocate runtime Class objects, so obj.class
on a obj_<C> receiver had no resolution and emitted a cannot resolve call warning + literal 0. The two real consumers in
practice are interpolation in inspect/to_s and the
.to_s.split("::").last introspection shape — both work fine
if .class simply yields the class name as a string.
Two sites updated:
infer_call_type:obj_<C>.classinfers asstring.compile_object_method_expr: emitc_string_literal(cname)for the call.
Cosmetic note: nested module classes render with the
underscore-flattened name (Optcarrot_NES) rather than the
original Optcarrot::NES. Not lossless, but sufficient for the
optcarrot warning sites.
Suppresses 7 of the optcarrot make optcarrot warnings.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 3d99fa63c024
- Parent
- 82d5cace65d9
spinel_codegen.rbmodifiedView file
end end # `<obj>.class` returns the class name as a string (Spinel # collapses Class/Module objects to their textual name; the # only consumers in practice are interpolation # `"#<#{self.class}>"` and `.to_s.split` chains, both of # which work fine on a plain string). if recv >= 0 && mname == "class" rt = infer_type(recv) if is_obj_type(rt) == 1 return "string" end end # `recv.__sp_ieval_<N>(...)`: the rewritten form of an # `recv.instance_eval { ... }` call. v1 only fired on top-level call # sites, where the call's value was always discarded — so its return if @cls_is_value_type[ci] == 1 arrow = "." end # `<obj>.class` — collapse to the class name as a string # literal. Spinel doesn't allocate runtime Class objects, # but the typical consumers (interpolation in inspect, # `.to_s.split("::").last` shape) all treat the result as # a string. Underscore-flattened nested module names # (`Optcarrot_NES`) render as-is rather than the original # `Optcarrot::NES` form; the loss is cosmetic. if mname == "class" return c_string_literal(cname) end # attr_reader readers = @cls_attr_readers[ci].split(";") j = 0test/obj_class_returns_string.rbaddedView file
Loading diff…
test/obj_class_returns_string.rb.expectedaddedView file
Loading diff…