Commit a3d3929b

a3d3929b5c9aMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 5 files · +2 added · ~3 modified

Description

Resolve implicit-self send(:literal) to a direct call

send(:m, args) / __send__("m", args) / public_send(:m, args) with no explicit receiver now lowers to a direct implicit-self call to m with the remaining args, the same static model as the existing textual recv.send(:m) receiver rewrite. Previously only the explicit-receiver form worked; bare send(:foo) (at top level or inside a method) failed to resolve.

Done as an AST desugar pass (analyze) rather than a textual rewrite: the bare send token has no . anchor, so a textual rule would mis-rewrite a send(: that appears inside a string literal or comment. A non-literal name (send(meth)) has no static target and is left alone.

Refs #1261.

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
a3d3929b5c9a
Parent
0a07a1f61a51

src/analyze.cmodifiedView file

@@ -1535,6 +1535,7 @@
15351535 ch |= infer_string_params(c);
15361536 ch |= infer_default_param_types(c);
15371537 ch |= desugar_enum_chain_to_a(c); /* each_slice(n).to_a -> .map{|s|s} */
1538+ ch |= desugar_implicit_send(c); /* send(:m, a) -> m(a) on self */
15381539 ch |= desugar_value_callable_forwards(c); /* &proc -> { |x| proc.call(x) } */
15391540 ch |= infer_block_params(c);
15401541 ch |= infer_for_index(c);