Commit 1d1ce513
1d1ce513cda5Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
fix(analyze,codegen): Class#name resolves inside def self.X body
Closes #509. Inside def self.X, both bare name and
self.name previously emitted cannot resolve call to 'name'
warnings. CRuby's Class#name returns the class's source name
as a string; spinel's existing recv_type == "class" dispatch
handled the Foo.name form via the class-typed constant
receiver, but the cmeth-body bare and self.name shapes both
fell through.
Three coordinated changes, gated on @current_method_has_self == 0 && @current_class_idx >= 0 (the cmeth context):
-
analyze (infer_call_type / "name" arm): both bare and SelfNode-receiver shapes return "string".
-
codegen compile_no_recv_call_expr: bare
nameemitssp_class_to_s({cls_id_for_user_internal(idx)}). -
codegen compile_object_method_expr: when
self.namereaches the obj-dispatch with self typed obj_, short-circuit to sp_class_to_s before the no-arm warning.
Roundhouse hit this in ActiveRecord::Base's "must be overridden"
raises (4 sites under table_name / schema_columns /
ApplicationRecord.*), where the embedded class name was empty.
Local: 478 tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 1d1ce513cda5
- Parent
- 7f773aa8dea4
spinel_analyze.rbmodifiedView file
if recv >= 0 && infer_type(recv) == "class" return "string" end # Bare `name` inside `def self.X` body. The implicit recv is # the class. SelfNode there infers as obj_<C>, so this path # is needed for the bare form and (separately) the explicit # `self.name` shape. Issue #509. if @current_method_name != "" && @current_class_idx >= 0 && @current_method_has_self == 0 return "string" end if recv >= 0 && @nd_type[recv] == "SelfNode" && @current_class_idx >= 0 && @current_method_has_self == 0 return "string" end end # hierarchy queries on a Class value. # .superclass -> class (the parent or sp_Class{-1})spinel_codegen.rbmodifiedView file
Loading diff…
test/class_name_in_cmeth.rbaddedView file
Loading diff…
test/class_name_in_cmeth.rb.expectedaddedView file
Loading diff…