[#109207] [Ruby master Feature#18915] New error class: NotImplementedYetError or scope change for NotImplementedYet — Quintasan <noreply@...>
Issue #18915 has been reported by Quintasan (Michał Zając).
18 messages
2022/07/14
[ruby-core:109386] [Ruby master Bug#18950] Hash#slice fails to copy default block
From:
"RubyBugs (A Nonymous)" <noreply@...>
Date:
2022-07-30 19:23:06 UTC
List:
ruby-core #109386
Issue #18950 has been reported by RubyBugs (A Nonymous).
----------------------------------------
Bug #18950: Hash#slice fails to copy default block
https://bugs.ruby-lang.org/issues/18950
* Author: RubyBugs (A Nonymous)
* Status: Open
* Priority: Normal
* ruby -v: 2.7.6
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
An intense weekend debugging session discovered the following root cause of a bug: `Hash#slice` returns a new Hash, which has no default block set, even if the source Hash did have a default block set.
Simplified code to reproduce:
``` ruby
# Default to an empty hash for all accessed keys
hash_with_default = Hash.new { |h, k| h[k] = {} } # => {}
hash_with_default[:a] # => {}
hash_with_default[:b] # => {}
hash_with_default # => {:a=>{}, :b=>{}}
# Later, use Hash#slice
hash_sliced = hash_with_default.slice(:a, :b) # => {:a=>{}, :b=>{}}
# Finally, access a new key
hash_sliced[:c] # => nil
# Error -- that was expected to call the default block
raise "No default value" unless hash_sliced[:c] == {}
```
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>