Commit 22d92395

22d92395b987Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified

Description

Pack call-site keywords into a required hash parameter

Article.new(title: "Hello", body: "World") with def initialize(attrs) previously dropped the keyword hash: the kwh-as-implicit-hash-argument path required the parameter to be optional (a default), so a required hash-typed positional param fell through to its default (NULL). Ruby packs trailing keywords into such a parameter; emit_args_filled now does too.

Fixes bundle_classd_13. The test suite is now 845 pass / 0 fail / 0 error.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
22d92395b987
Parent
36ad51efee59

src/codegen.cmodifiedView file

@@ -3176,13 +3176,14 @@
31763176 emit_arg_or_default(c, m, i, argv[i], out);
31773177 }
31783178 else {
3179- /* No positional arg and no keyword match. If the param is a hash-typed
3180- optional (e.g. `def f(opts = {})`) and the call site passed a
3181- KeywordHashNode (e.g. `f(key: val)`), treat the whole kwh as the
3179+ /* No positional arg and no keyword match. If the param is hash-typed
3180+ (required `def f(attrs)` or optional `def f(opts = {})`) and the
3181+ call site passed a KeywordHashNode (e.g. `f(key: val)`), Ruby packs
3182+ the keywords into that hash parameter -- treat the whole kwh as the
31823183 implicit hash argument rather than using the default. */
31833184 LocalVar *p = scope_local(m, m->pnames[i]);
31843185 TyKind pt = p ? p->type : TY_INT;
3185- int use_kwh = (kwh >= 0 && ty_is_hash(pt) && m->pdefault[i] >= 0);
3186+ int use_kwh = (kwh >= 0 && ty_is_hash(pt));
31863187 emit_arg_or_default(c, m, i, use_kwh ? kwh : -1, out);
31873188 }
31883189 }