[#114181] [Ruby master Bug#19767] [Not really a bug, but more a not ideal notification] "historical binary regexp match" when using the "n" modifier in a ruby regex — "rubyFeedback (robert heiler) via ruby-core" <ruby-core@...>
SXNzdWUgIzE5NzY3IGhhcyBiZWVuIHJlcG9ydGVkIGJ5IHJ1YnlGZWVkYmFjayAocm9iZXJ0IGhl
3 messages
2023/07/14
[ruby-core:114269] [Ruby master Bug#19759] Surprising automatic splat with ruby2_keywords_hash
From:
"nagachika (Tomoyuki Chikanaga) via ruby-core" <ruby-core@...>
Date:
2023-07-23 04:03:59 UTC
List:
ruby-core #114269
Issue #19759 has been updated by nagachika (Tomoyuki Chikanaga).
Backport changed from 3.0: UNKNOWN, 3.1: REQUIRED, 3.2: REQUIRED to 3.0: UNKNOWN, 3.1: REQUIRED, 3.2: DONE
ruby_3_2 3354aacb73c65420a10cb41c0696e62dd1ba279b merged revision(s) 3874381c4483ba7794ac2abf157e265546f9bfa7.
----------------------------------------
Bug #19759: Surprising automatic splat with ruby2_keywords_hash
https://bugs.ruby-lang.org/issues/19759#change-103960
* Author: alanwu (Alan Wu)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
* Backport: 3.0: UNKNOWN, 3.1: REQUIRED, 3.2: DONE
----------------------------------------
On Ruby 3 and newer the following prints `[:aa, :bb, :k]`:
```ruby
def yielder(splat)
yield([:a, :b], *splat)
end
yielder([[:aa, :bb], Hash.ruby2_keywords_hash({k: :k})]) do |a, b, k:|
p [a, b, k]
end
```
It expanded the second array involved and `[:a, :b]` vanished.
This is surprising because automatic array expansion for blocks
used to only happen when passing one array in total.
The script prints `[[:a, :b], [:aa, :bb], :k]` with 2.7.3.
---
I found this while puzzling over this line in the autosplat logic:
```c
if (given_argc == (NIL_P(keyword_hash) ? 1 : 2) &&
```
It might be tempting to fix it by reversing part of commit:beae6cbf0fd and make it `if (given_argc == 1)`.
However that's incorrect due to inducing a behavior change for cases like
`yield(*[[:a, :b], keywords_hash])`.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/