ruby-changes:57995
From: Jeremy <ko1@a...>
Date: Sat, 28 Sep 2019 03:22:10 +0900 (JST)
Subject: [ruby-changes:57995] 7814b6c657 (master): Correctly issue ArgumentError when calling method that accepts no keywords
https://git.ruby-lang.org/ruby.git/commit/?id=7814b6c657 From 7814b6c6572446a6b64614e524d13dd423577004 Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Fri, 27 Sep 2019 09:35:51 -0700 Subject: Correctly issue ArgumentError when calling method that accepts no keywords If a method accepts no keywords and was called with a keyword, an ArgumentError was not always issued previously. Force methods that accept no keywords to go through setup_parameters_complex so that an ArgumentError is raised if keywords are provided. diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb index 5992434..1a445cd 100644 --- a/test/ruby/test_keyword.rb +++ b/test/ruby/test_keyword.rb @@ -158,6 +158,19 @@ class TestKeywordArguments < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L158 assert_equal([b, [:b]], f12(**h, &b)) end + def f13(a, **nil) + a + end + + def test_f13 + assert_equal(1, f13(1)) + assert_equal(1, f13(1, **{})) + assert_raise(ArgumentError) { f13(a: 1) } + assert_raise(ArgumentError) { f13(1, a: 1) } + assert_raise(ArgumentError) { f13(**{a: 1}) } + assert_raise(ArgumentError) { f13(1, **{a: 1}) } + end + def test_method_parameters assert_equal([[:key, :str], [:key, :num]], method(:f1).parameters); assert_equal([[:req, :x], [:key, :str], [:key, :num]], method(:f2).parameters); diff --git a/vm_insnhelper.c b/vm_insnhelper.c index fdcf3d4..4375a48 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1743,6 +1743,7 @@ rb_simple_iseq_p(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1743 iseq->body->param.flags.has_post == FALSE && iseq->body->param.flags.has_kw == FALSE && iseq->body->param.flags.has_kwrest == FALSE && + iseq->body->param.flags.accepts_no_kwarg == FALSE && iseq->body->param.flags.has_block == FALSE; } @@ -1754,6 +1755,7 @@ rb_iseq_only_optparam_p(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1755 iseq->body->param.flags.has_post == FALSE && iseq->body->param.flags.has_kw == FALSE && iseq->body->param.flags.has_kwrest == FALSE && + iseq->body->param.flags.accepts_no_kwarg == FALSE && iseq->body->param.flags.has_block == FALSE; } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/