Commit 940dc298
940dc2986209Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · ~2 modified
Description
fix(codegen): bare sibling cmeth call inside def self.X resolves
A bare mname(args) inside def self.X previously tripped the
"cannot resolve call to 'mname' on (no receiver) (emitting 0)"
warning, with the callee's params defaulting to mrb_int because no
call site contributed a typing signal. CRuby/JRuby/mruby treat the
bare call as self.mname(...), dispatching to the same module /
class's other class methods.
Three coordinated changes mirror that:
-
compile_no_recv_call_exprnow resolves bare calls against the sibling cmeth tables. Module case: @current_method_name carries the synthetic<Mod>_cls_<m>form; the marker scan extracts the owner and looks the sibling up in @meth_*. Real-class case: emit_class_level_method sets only @current_class_idx + @current_method_has_self = 0 (no marker on @current_method_name), so the second arm gates on those signals and looks the sibling up in @cls_cmeth_names. -
infer_type's bare-call arm grew the same sibling-resolution path so callers likelv_y = inner(lv_x)infer a string return (instead of the int default), letting scan_locals declare lv_y correctly the first time around. -
scan_new_calls's CallNode arm grew a parallel sibling-widening block alongside the existing inherited-instance-method one, so the bare call's args feed widen_ptypes_from_args on the callee's @cls_cmeth_ptypes (real class) or @meth_param_types entry (module synth name). Without this the callee's params stayed at mrb_int even after the dispatch resolved.
Test bare_sibling_cls_method_call.rb covers (a) the module shape from the issue (outer cmeth bare-calling a string-typed sibling), (b) the real-class form for the @cls_cmeth_* path, and (c) a multi-hop chain (start -> middle -> finish) so the iterative inference loop has to propagate types past the immediate sibling to cover transitive bare-call shapes.
Closes #405
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 940dc2986209
- Parent
- fa72f5e3d3df
spinel_analyze.rbmodifiedView file
if mi_user >= 0 return @meth_return_types[mi_user] end # Issue #405: bare call inside a `def self.X` body resolves to # a sibling cmeth on the same class/module. Two signals reach # here at different stages: inference sets @current_method_name # to "<Class>_cls_<m>" (so the marker scan succeeds); emission # sets only @current_method_has_self == 0 + @current_class_idx # for real-class cmeths (with @current_method_name = plain # mname, no marker). if @current_method_name != "" mark_cm_405 = @current_method_name.index("_cls_") if mark_cm_405 != nil && mark_cm_405 >= 0 owning_cm_405 = @current_method_name[0, mark_cm_405] if module_name_exists(owning_cm_405) == 1 synth_cm_405 = owning_cm_405 + "_cls_" + mname mi_cm_405 = find_method_idx(synth_cm_405) if mi_cm_405 >= 0 return @meth_return_types[mi_cm_405] end end cci_cm_405 = find_class_idx(owning_cm_405) if cci_cm_405 >= 0 cmnames_cm_405 = @cls_cmeth_names[cci_cm_405].split(";") cmreturns_cm_405 = @cls_cmeth_returns[cci_cm_405].split(";") cmidx_cm_405 = 0 while cmidx_cm_405 < cmnames_cm_405.length if cmnames_cm_405[cmidx_cm_405] == mname && cmidx_cm_405 < cmreturns_cm_405.length return cmreturns_cm_405[cmidx_cm_405] end cmidx_cm_405 = cmidx_cm_405 + 1 end end end end if @current_class_idx >= 0 && @current_method_has_self == 0 cmnames_cm_405r = @cls_cmeth_names[@current_class_idx].split(";") cmreturns_cm_405r = @cls_cmeth_returns[@current_class_idx].split(";") cmidx_cm_405r = 0 while cmidx_cm_405r < cmnames_cm_405r.length if cmnames_cm_405r[cmidx_cm_405r] == mname && cmidx_cm_405r < cmreturns_cm_405r.length return cmreturns_cm_405r[cmidx_cm_405r] end cmidx_cm_405r = cmidx_cm_405r + 1 end end end # Method name-based type inference end end end # Issue #405: bare call inside a `def self.X` body resolves # to a sibling cmeth on the same class/module. Widen the # sibling's ptypes from this call site's args. Mirrors the # explicit-`M.X(args)` widening branch below but keyed off # @current_method_name's `<Class>_cls_<m>` marker (set by # infer_function_body_call_types / infer_class_body_call_types # before walking each cmeth body) since recv is absent here. if @current_method_name != "" marker_405 = @current_method_name.index("_cls_") if marker_405 != nil && marker_405 >= 0 owning_405 = @current_method_name[0, marker_405] cci_405 = find_class_idx(owning_405) if cci_405 >= 0 cmnames_405 = @cls_cmeth_names[cci_405].split(";") cmidx_405 = 0 while cmidx_405 < cmnames_405.length if cmnames_405[cmidx_405] == mname args_id_405 = @nd_arguments[nid] if args_id_405 >= 0 arg_ids_405 = get_args(args_id_405) cmpt_405 = cls_cmeth_ptypes_get(cci_405, cmidx_405) if cmpt_405.length > 0 cmpn_405 = cls_cmeth_pnames_get(cci_405, cmidx_405) widen_ptypes_from_args(arg_ids_405, cmpn_405, cmpt_405) cls_cmeth_ptypes_put(cci_405, cmidx_405, cmpt_405) end end end cmidx_405 = cmidx_405 + 1 end end if module_name_exists(owning_405) == 1 synth_405 = owning_405 + "_cls_" + mname sib_mi_405m = find_method_idx(synth_405) if sib_mi_405m >= 0 args_id_405m = @nd_arguments[nid] if args_id_405m >= 0 arg_ids_405m = get_args(args_id_405m) ptypes_405m = @meth_param_types[sib_mi_405m].split(",") pnames_405m = @meth_param_names[sib_mi_405m].split(",") widen_ptypes_from_args(arg_ids_405m, pnames_405m, ptypes_405m) @meth_param_types[sib_mi_405m] = ptypes_405m.join(",") end end end end end end if @nd_name[nid] == "new" recv = @nd_receiver[nid]spinel_codegen.rbmodifiedView file
Loading diff…