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 name emits sp_class_to_s({cls_id_for_user_internal(idx)}).

  • codegen compile_object_method_expr: when self.name reaches 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

@@ -3391,6 +3391,16 @@
33913391 if recv >= 0 && infer_type(recv) == "class"
33923392 return "string"
33933393 end
3394+ # Bare `name` inside `def self.X` body. The implicit recv is
3395+ # the class. SelfNode there infers as obj_<C>, so this path
3396+ # is needed for the bare form and (separately) the explicit
3397+ # `self.name` shape. Issue #509.
3398+ if @current_method_name != "" && @current_class_idx >= 0 && @current_method_has_self == 0
3399+ return "string"
3400+ end
3401+ if recv >= 0 && @nd_type[recv] == "SelfNode" && @current_class_idx >= 0 && @current_method_has_self == 0
3402+ return "string"
3403+ end
33943404 end
33953405 # hierarchy queries on a Class value.
33963406 # .superclass -> class (the parent or sp_Class{-1})