Project

General

Profile

Feature #10118 ยป 0001-vm.c-allow-to-splat-non-symbol-keys.patch

nobu (Nobuyoshi Nakada), 08/09/2014 12:49 AM

View differences:

test/ruby/test_syntax.rb
h = {k3: 31}
assert_raise(ArgumentError) {o.kw(**h)}
h = {"k1"=>11, k2: 12}
assert_raise(TypeError) {o.kw(**h)}
assert_raise(ArgumentError) {o.kw(**h)}
assert_equal({"k1"=>11, :"k2"=>12, :"k3"=>31}, {k3: 31, **h})
assert_equal({"k1"=>11, :"k2"=>12}, {**h})
end
def test_keyword_self_reference
vm.c
static int
kwmerge_i(VALUE key, VALUE value, VALUE hash)
{
if (!SYMBOL_P(key)) Check_Type(key, T_SYMBOL);
if (st_update(RHASH_TBL_RAW(hash), key, kwmerge_ii, (st_data_t)value) == 0) { /* !existing */
RB_OBJ_WRITTEN(hash, Qundef, value);
}
return ST_CONTINUE;
}
static int
kwcheck_i(VALUE key, VALUE value, VALUE hash)
{
if (!SYMBOL_P(key)) Check_Type(key, T_SYMBOL);
return ST_CONTINUE;
}
static VALUE
m_core_hash_merge_kwd(int argc, VALUE *argv, VALUE recv)
{
......
kw = argv[argc-1];
kw = rb_convert_type(kw, T_HASH, "Hash", "to_hash");
if (argc < 2) hash = kw;
rb_hash_foreach(kw, argc < 2 ? kwcheck_i : kwmerge_i, hash);
else rb_hash_foreach(kw, kwmerge_i, hash);
return hash;
}
    (1-1/1)