<feed xmlns='http://www.w3.org/2005/Atom'>
<title>ruby.git/test/ruby/test_keyword.rb, branch v3_3_11</title>
<subtitle>The Ruby Programming Language</subtitle>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/'/>
<entry>
<title>merge revision(s) ce849d565bf6aae8e0179fffb04eb1f665f17347, acb29f7fa1497463ed3bdd65549ef20b61beda64: [Backport #21402]</title>
<updated>2025-09-14T03:47:12+00:00</updated>
<author>
<name>nagachika</name>
<email>nagachika@ruby-lang.org</email>
</author>
<published>2025-09-14T03:47:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=e39a0a19c03fbb37d1c9d1e050bb551dccfc11c6'/>
<id>e39a0a19c03fbb37d1c9d1e050bb551dccfc11c6</id>
<content type='text'>
	ruby2_keywords warnings: Quote non-UTF8 method names fully

	It used to quote only part of the method name because NUL byte in
	the method terminates the C string:

	```
	(irb)&gt; "abcdef".encode("UTF-16LE").bytes
	=&gt; [97, 0, 98, 0, 99, 0, 100, 0, 101, 0, 102, 0]
	```

	```
	expected: /abcdef/
	actual: warning: Skipping set of ruby2_keywords flag for a (method not defined in Ruby)\n".
	```

	Do not respect ruby2_keywords on method/proc with post arguments

	Previously, ruby2_keywords could be used on a method or proc with
	post arguments, but I don't think the behavior is desired:

	```ruby
	def a(*c, **kw) [c, kw] end
	def b(*a, b) a(*a, b) end
	ruby2_keywords(:b)

	b({foo: 1}, bar: 1)
	```

	This changes ruby2_keywords to emit a warning and not set the
	flag on a method/proc with post arguments.

	While here, fix the ruby2_keywords specs for warnings, since they
	weren't testing what they should be testing.  They all warned
	because the method didn't accept a rest argument, not because it
	accepted a keyword or keyword rest argument.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
	ruby2_keywords warnings: Quote non-UTF8 method names fully

	It used to quote only part of the method name because NUL byte in
	the method terminates the C string:

	```
	(irb)&gt; "abcdef".encode("UTF-16LE").bytes
	=&gt; [97, 0, 98, 0, 99, 0, 100, 0, 101, 0, 102, 0]
	```

	```
	expected: /abcdef/
	actual: warning: Skipping set of ruby2_keywords flag for a (method not defined in Ruby)\n".
	```

	Do not respect ruby2_keywords on method/proc with post arguments

	Previously, ruby2_keywords could be used on a method or proc with
	post arguments, but I don't think the behavior is desired:

	```ruby
	def a(*c, **kw) [c, kw] end
	def b(*a, b) a(*a, b) end
	ruby2_keywords(:b)

	b({foo: 1}, bar: 1)
	```

	This changes ruby2_keywords to emit a warning and not set the
	flag on a method/proc with post arguments.

	While here, fix the ruby2_keywords specs for warnings, since they
	weren't testing what they should be testing.  They all warned
	because the method didn't accept a rest argument, not because it
	accepted a keyword or keyword rest argument.
</pre>
</div>
</content>
</entry>
<entry>
<title>merge revision(s) fc33559c: [Backport #20570]</title>
<updated>2024-07-08T23:08:42+00:00</updated>
<author>
<name>Takashi Kokubun</name>
<email>takashikkbn@gmail.com</email>
</author>
<published>2024-07-08T23:08:42+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=17e21d815583ef7d6be03f29e90a219602497626'/>
<id>17e21d815583ef7d6be03f29e90a219602497626</id>
<content type='text'>
	clear `kw_flag` if given hash is nil

	https://bugs.ruby-lang.org/issues/20570 is caused I missed to
	clear the `kw_flag` even if `keyword_hash` is nil.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
	clear `kw_flag` if given hash is nil

	https://bugs.ruby-lang.org/issues/20570 is caused I missed to
	clear the `kw_flag` even if `keyword_hash` is nil.
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix keyword splat passing as regular argument</title>
<updated>2023-12-07T16:35:55+00:00</updated>
<author>
<name>Jeremy Evans</name>
<email>code@jeremyevans.net</email>
</author>
<published>2023-12-07T16:35:55+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=ca204a20231f1ecabf5a7343aec49c3ea1bac90a'/>
<id>ca204a20231f1ecabf5a7343aec49c3ea1bac90a</id>
<content type='text'>
Since Ruby 3.0, Ruby has passed a keyword splat as a regular
argument in the case of a call to a Ruby method where the
method does not accept keyword arguments, if the method
call does not contain an argument splat:

```ruby
def self.f(obj) obj end
def self.fs(*obj) obj[0] end
h = {a: 1}
f(**h).equal?(h)  # Before: true; After: false
fs(**h).equal?(h) # Before: true; After: false

a = []
f(*a, **h).equal?(h)  # Before and After: false
fs(*a, **h).equal?(h) # Before and After: false
```

The fact that the behavior differs when passing an empty
argument splat makes it obvious that something is not
working the way it is intended.  Ruby 2 always copied
the keyword splat hash, and that is the expected behavior
in Ruby 3.

This bug is because of a missed check in setup_parameters_complex.
If the keyword splat passed is not mutable, then it points to
an existing object and not a new object, and therefore it must
be copied.

Now, there are 3 specs for the broken behavior of directly
using the keyword splatted hash.  Fix two specs and add a
new version guard. Do not keep the specs for the broken
behavior for earlier Ruby versions, in case this fix is
backported. For the ruby2_keywords spec, just remove the
related line, since that line is unrelated to what the
spec is testing.

Co-authored-by: Nobuyoshi Nakada &lt;nobu@ruby-lang.org&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Since Ruby 3.0, Ruby has passed a keyword splat as a regular
argument in the case of a call to a Ruby method where the
method does not accept keyword arguments, if the method
call does not contain an argument splat:

```ruby
def self.f(obj) obj end
def self.fs(*obj) obj[0] end
h = {a: 1}
f(**h).equal?(h)  # Before: true; After: false
fs(**h).equal?(h) # Before: true; After: false

a = []
f(*a, **h).equal?(h)  # Before and After: false
fs(*a, **h).equal?(h) # Before and After: false
```

The fact that the behavior differs when passing an empty
argument splat makes it obvious that something is not
working the way it is intended.  Ruby 2 always copied
the keyword splat hash, and that is the expected behavior
in Ruby 3.

This bug is because of a missed check in setup_parameters_complex.
If the keyword splat passed is not mutable, then it points to
an existing object and not a new object, and therefore it must
be copied.

Now, there are 3 specs for the broken behavior of directly
using the keyword splatted hash.  Fix two specs and add a
new version guard. Do not keep the specs for the broken
behavior for earlier Ruby versions, in case this fix is
backported. For the ruby2_keywords spec, just remove the
related line, since that line is unrelated to what the
spec is testing.

Co-authored-by: Nobuyoshi Nakada &lt;nobu@ruby-lang.org&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>`Hash#dup` for kwsplat arguments</title>
<updated>2023-03-15T09:05:13+00:00</updated>
<author>
<name>Koichi Sasada</name>
<email>ko1@atdot.net</email>
</author>
<published>2023-03-13T18:42:47+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=6462c1a042fec4017f7e3bf2c13ec6a29efd23d6'/>
<id>6462c1a042fec4017f7e3bf2c13ec6a29efd23d6</id>
<content type='text'>
On `f(*a, **kw)` method calls, a rest keyword parameter is identically
same Hash object is passed and it should make `#dup`ed Hahs.

fix https://bugs.ruby-lang.org/issues/19526
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
On `f(*a, **kw)` method calls, a rest keyword parameter is identically
same Hash object is passed and it should make `#dup`ed Hahs.

fix https://bugs.ruby-lang.org/issues/19526
</pre>
</div>
</content>
</entry>
<entry>
<title>Rename method name in keyword test from y to yo</title>
<updated>2022-09-26T19:00:40+00:00</updated>
<author>
<name>Jeremy Evans</name>
<email>code@jeremyevans.net</email>
</author>
<published>2022-09-26T17:53:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=b39690df3a90a838cdb2de71e70a20651ebafaf4'/>
<id>b39690df3a90a838cdb2de71e70a20651ebafaf4</id>
<content type='text'>
Kernel#y is defined by psych/yaml, which causes occasional
nondeterministic problems with this test when doing parallel testing.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Kernel#y is defined by psych/yaml, which causes occasional
nondeterministic problems with this test when doing parallel testing.
</pre>
</div>
</content>
</entry>
<entry>
<title>test/ruby/test_keyword.rb: Prevent warning: assigned but unused variable</title>
<updated>2022-04-11T01:05:16+00:00</updated>
<author>
<name>Yusuke Endoh</name>
<email>mame@ruby-lang.org</email>
</author>
<published>2022-04-11T01:05:16+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=44a911a293ca6448f9e029e22492e78a1828a16b'/>
<id>44a911a293ca6448f9e029e22492e78a1828a16b</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Unflag a splatted flagged hash if the method doesn't use ruby2_keywords</title>
<updated>2022-04-05T09:42:02+00:00</updated>
<author>
<name>Jeremy Evans</name>
<email>code@jeremyevans.net</email>
</author>
<published>2022-03-11T21:49:36+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=752c3dad989bb66e4be61911a82fed992067bdc3'/>
<id>752c3dad989bb66e4be61911a82fed992067bdc3</id>
<content type='text'>
For a method such as:

  def foo(*callee_args) end

If this method is called with a flagged hash (created by a method
flagged with ruby2_keywords), this previously passed the hash
through without modification.  With this change, it acts as if the
last hash was passed as keywords, so a call to:

  foo(*caller_args)

where the last element of caller_args is a flagged hash, will be
treated as:

  foo(*caller_args[0...-1], **caller_args[-1])

As a result, inside foo, callee_args[-1] is an unflagged duplicate
of caller_args[-1] (all other elements of callee_args match
caller_args).

Fixes [Bug #18625]
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
For a method such as:

  def foo(*callee_args) end

If this method is called with a flagged hash (created by a method
flagged with ruby2_keywords), this previously passed the hash
through without modification.  With this change, it acts as if the
last hash was passed as keywords, so a call to:

  foo(*caller_args)

where the last element of caller_args is a flagged hash, will be
treated as:

  foo(*caller_args[0...-1], **caller_args[-1])

As a result, inside foo, callee_args[-1] is an unflagged duplicate
of caller_args[-1] (all other elements of callee_args match
caller_args).

Fixes [Bug #18625]
</pre>
</div>
</content>
</entry>
<entry>
<title>Do not autosplat array in block call just because keywords accepted</title>
<updated>2022-03-30T18:03:56+00:00</updated>
<author>
<name>Jeremy Evans</name>
<email>code@jeremyevans.net</email>
</author>
<published>2022-03-30T18:03:56+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=fbaadd1cfe7fbfd1b904f193f99d7c845a6ed804'/>
<id>fbaadd1cfe7fbfd1b904f193f99d7c845a6ed804</id>
<content type='text'>
If the block only accepts a single positional argument plus keywords,
then do not autosplat.  Still autosplat if the block accepts more
than one positional argument in addition to keywords.

Autosplatting a single positional argument plus keywords made sense
in Ruby 2, since a final positional hash could be used as keywords,
but it does not make sense in Ruby 3.

Fixes [Bug #18633]</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
If the block only accepts a single positional argument plus keywords,
then do not autosplat.  Still autosplat if the block accepts more
than one positional argument in addition to keywords.

Autosplatting a single positional argument plus keywords made sense
in Ruby 2, since a final positional hash could be used as keywords,
but it does not make sense in Ruby 3.

Fixes [Bug #18633]</pre>
</div>
</content>
</entry>
<entry>
<title>Adds mixed hash value and value omission tests</title>
<updated>2021-09-13T04:54:03+00:00</updated>
<author>
<name>Brandon Weaver</name>
<email>keystonelemur@gmail.com</email>
</author>
<published>2021-09-13T03:34:28+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=4676921730bd257c234396fd9134ae9876043756'/>
<id>4676921730bd257c234396fd9134ae9876043756</id>
<content type='text'>
Introduces specification tests for mixed values and value omissions for
Hashes and keyword arguments, such as `{ a:, b:, c: 3 }`.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Introduces specification tests for mixed values and value omissions for
Hashes and keyword arguments, such as `{ a:, b:, c: 3 }`.
</pre>
</div>
</content>
</entry>
<entry>
<title>Add documentation and tests for keyword argument value omission</title>
<updated>2021-09-11T11:23:36+00:00</updated>
<author>
<name>Shugo Maeda</name>
<email>shugo@ruby-lang.org</email>
</author>
<published>2021-09-11T11:23:36+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=297f9b8d4c4502aa2ba0eccf93dfce215a7b6dfe'/>
<id>297f9b8d4c4502aa2ba0eccf93dfce215a7b6dfe</id>
<content type='text'>
[Feature #14579]
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[Feature #14579]
</pre>
</div>
</content>
</entry>
</feed>
