summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/ruby/test_allocation.rb12
-rw-r--r--vm_args.c17
2 files changed, 22 insertions, 7 deletions
diff --git a/test/ruby/test_allocation.rb b/test/ruby/test_allocation.rb
index 6534c123fb..fa12bf481b 100644
--- a/test/ruby/test_allocation.rb
+++ b/test/ruby/test_allocation.rb
@@ -273,7 +273,7 @@ class TestAllocation < Test::Unit::TestCase
check_allocations(0, 1, "keyword(**hash1, **empty_hash#{block})")
check_allocations(1, 0, "keyword(*empty_array, *empty_array, **empty_hash#{block})")
- check_allocations(1, 0, "keyword(*r2k_empty_array#{block})")
+ check_allocations(0, 0, "keyword(*r2k_empty_array#{block})")
check_allocations(1, 1, "keyword(*r2k_array#{block})")
check_allocations(0, 1, "keyword(*empty_array, a: 2, **empty_hash#{block})")
@@ -379,7 +379,7 @@ class TestAllocation < Test::Unit::TestCase
check_allocations(1, 1, "required_and_keyword(*array1, *empty_array, a: 2, **empty_hash#{block})")
check_allocations(1, 1, "required_and_keyword(*array1, *empty_array, **hash1, **empty_hash#{block})")
- check_allocations(1, 0, "required_and_keyword(*r2k_empty_array1#{block})")
+ check_allocations(0, 0, "required_and_keyword(*r2k_empty_array1#{block})")
check_allocations(1, 1, "required_and_keyword(*r2k_array1#{block})")
# Currently allocates 1 array unnecessarily due to splatarray true
@@ -724,7 +724,7 @@ class TestAllocation < Test::Unit::TestCase
check_allocations(1, 1, "r2k(1, **empty_hash, a: 2#{block})")
check_allocations(1, 0, "r2k(1, **nil#{block})")
- check_allocations(1, 1, "r2k(1, **empty_hash#{block})")
+ check_allocations(1, 0, "r2k(1, **empty_hash#{block})")
check_allocations(1, 1, "r2k(1, **hash1#{block})")
check_allocations(1, 1, "r2k(1, *empty_array, **hash1#{block})")
check_allocations(1, 1, "r2k(1, **hash1, **empty_hash#{block})")
@@ -732,17 +732,17 @@ class TestAllocation < Test::Unit::TestCase
check_allocations(1, 0, "r2k(1, *empty_array#{block})")
check_allocations(1, 1, "r2k(1, **hash1, **empty_hash#{block})")
- check_allocations(1, 1, "r2k(1, *empty_array, *empty_array, **empty_hash#{block})")
+ check_allocations(1, 0, "r2k(1, *empty_array, *empty_array, **empty_hash#{block})")
check_allocations(1, 1, "r2k(*array1, a: 2#{block})")
check_allocations(1, 0, "r2k(*array1, **nill#{block})")
- check_allocations(1, 1, "r2k(*array1, **empty_hash#{block})")
+ check_allocations(1, 0, "r2k(*array1, **empty_hash#{block})")
check_allocations(1, 1, "r2k(*array1, **hash1#{block})")
check_allocations(1, 1, "r2k(*array1, *empty_array, **hash1#{block})")
check_allocations(1, 0, "r2k(*array1, *empty_array#{block})")
- check_allocations(1, 1, "r2k(*array1, *empty_array, **empty_hash#{block})")
+ check_allocations(1, 0, "r2k(*array1, *empty_array, **empty_hash#{block})")
check_allocations(1, 1, "r2k(*array1, *empty_array, a: 2, **empty_hash#{block})")
check_allocations(1, 1, "r2k(*array1, *empty_array, **hash1, **empty_hash#{block})")
diff --git a/vm_args.c b/vm_args.c
index b4a8fcb8fb..90105f6900 100644
--- a/vm_args.c
+++ b/vm_args.c
@@ -535,6 +535,10 @@ ignore_keyword_hash_p(VALUE keyword_hash, const rb_iseq_t * const iseq, unsigned
}
}
+ if (RHASH_EMPTY_P(keyword_hash) && !ISEQ_BODY(iseq)->param.flags.has_kwrest) {
+ goto ignore;
+ }
+
if (!(*kw_flag & VM_CALL_KW_SPLAT_MUT) &&
(ISEQ_BODY(iseq)->param.flags.has_kwrest ||
ISEQ_BODY(iseq)->param.flags.ruby2_keywords)) {
@@ -856,7 +860,18 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co
args_setup_kw_parameters_from_kwsplat(ec, iseq, keyword_hash, klocals, remove_hash_value);
}
else {
- VM_ASSERT(args_argc(args) == 0);
+#if VM_CHECK_MODE > 0
+ if (args_argc(args) != 0) {
+ VM_ASSERT(ci_flag & VM_CALL_ARGS_SPLAT);
+ VM_ASSERT(!(ci_flag & (VM_CALL_KWARG | VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT)));
+ VM_ASSERT(!kw_flag);
+ VM_ASSERT(!ISEQ_BODY(iseq)->param.flags.has_rest);
+ VM_ASSERT(RARRAY_LENINT(args->rest) > 0);
+ VM_ASSERT(RB_TYPE_P(rest_last, T_HASH));
+ VM_ASSERT(FL_TEST_RAW(rest_last, RHASH_PASS_AS_KEYWORDS));
+ VM_ASSERT(args_argc(args) == 1);
+ }
+#endif
args_setup_kw_parameters(ec, iseq, NULL, 0, NULL, klocals);
}
}