diff options
author | Jeremy Evans <code@jeremyevans.net> | 2020-02-24 13:19:37 -0800 |
---|---|---|
committer | NARUSE, Yui <naruse@airemix.jp> | 2020-03-15 19:35:24 +0900 |
commit | e70d52b0c377f8b2ed04311710c0ca9f4ebabd90 (patch) | |
tree | b02a277cc2dfeddfbd72ee06e70bdd24f897f1aa /vm_args.c | |
parent | b3fabedc7043593812c9ad507b4648a55d74df99 (diff) |
Make ruby2_keywords methods correctly handle **{} optimization
Previously, this code:
ruby2_keywords def foo(*a) a.last end
foo(**{})
Returned an empty frozen hash. However, the final hash should
not be frozen in this case, as it wouldn't be if foo accepted
a keyword splat.
Use a new unfrozen empty hash instead of reusing the frozen empty
hash in this case.
Fixes [Bug #16642]
Diffstat (limited to 'vm_args.c')
-rw-r--r-- | vm_args.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -821,6 +821,10 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co kw_flag &= ~VM_CALL_KW_SPLAT; } else { + if (RB_TYPE_P(rest_last, T_HASH) && rb_obj_frozen_p(rest_last)) { + rest_last = rb_hash_new(); + RARRAY_ASET(args->rest, len - 1, rest_last); + } flag_keyword_hash = rest_last; } } @@ -844,6 +848,10 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co kw_flag &= ~VM_CALL_KW_SPLAT; } else { + if (RB_TYPE_P(last_arg, T_HASH) && rb_obj_frozen_p(last_arg)) { + last_arg = rb_hash_new(); + args->argv[args->argc-1] = last_arg; + } flag_keyword_hash = last_arg; } } |