Commit f78c5792

f78c5792301dMerged

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

Description

fix(parse,codegen): public_send + send alias for send (#735)

recv.public_send(:foo, args) used to fall through to the unresolved-call warning. spinel's static dispatch doesn't model visibility, so public_send is semantically identical to send (and send). The parser textual-rewrite path already short-circuited .send(:foo) and .__send__(:foo) to .foo; extend it with two new entries for .public_send(:foo) and .public_send("foo").

Also widen the codegen-side AST rewrite arm (the path that catches SymbolNode args constructed via reflection) to recognise public_send and send alongside send. Belt-and-suspenders: in practice the parser-side textual rewrite already catches the literal-symbol shape, so the codegen change is a safety net for edge cases the parser path skips.

Test: test/public_send.rb covers public_send with symbol + string args + an int receiver + the unchanged send path.

472 tests pass; optcarrot checksum 59662.

Closes #735

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

Details

Commit
f78c5792301d
Parent
baa45caa6e94

spinel_codegen.rbmodifiedView file

@@ -14984,13 +14984,15 @@
1498414984 # outer CallNode's @nd_name and the inner ArgumentsNode's
1498514985 # @nd_args so the dispatch sees the actual method call
1498614986 # signature, then restore. Issue #555 case 12.
14987- if mname == "send" && recv >= 0
14987+ # `public_send` is identical to `send` for spinel (visibility is
14988+ # not modeled). Issue #735.
14989+ if (mname == "send" || mname == "public_send" || mname == "__send__") && recv >= 0
1498814990 args_id_send = @nd_arguments[nid]
1498914991 if args_id_send >= 0
1499014992 aa_send = get_args(args_id_send)
1499114993 if aa_send.length >= 1 && @nd_type[aa_send[0]] == "SymbolNode"
1499214994 sym_name_send = @nd_content[aa_send[0]]
14993- if sym_name_send != "" && sym_name_send != "send"
14995+ if sym_name_send != "" && sym_name_send != "send" && sym_name_send != "public_send" && sym_name_send != "__send__"
1499414996 saved_name_send = @nd_name[nid]
1499514997 saved_args_str = @nd_args[args_id_send]
1499614998 new_args_str = ""