Skip to content

Commit e845eda

Browse files
committed
[GR-19220] Ruby 3.2 Fix Hash#shift when Hash is empty but has default value or proc
PullRequest: truffleruby/3747
2 parents 81a536c + a397394 commit e845eda

File tree

6 files changed

+50
-56
lines changed

6 files changed

+50
-56
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Bug fixes:
88

99
Compatibility:
1010

11+
- Fix `Hash#shift` when Hash is empty but has initial default value or initial default proc (@itarato).
1112

1213
Performance:
1314

spec/tags/core/hash/shift_tags.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fails:Hash#shift calls #default with nil if the Hash is empty
2+
fails:Hash#shift returns (computed) default for empty hashes

spec/truffleruby.mspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class MSpecScript
104104
# Use spec/ruby/core/nil/nil_spec.rb as a dummy file to avoid being empty
105105
set :next, %w[
106106
spec/ruby/core/nil/nil_spec.rb
107+
spec/ruby/core/hash/shift_spec.rb
107108
]
108109

109110
set :tags_patterns, [

src/main/java/org/truffleruby/core/hash/HashNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,9 @@ protected Object setDefault(RubyHash hash, Object defaultValue,
511511
public abstract static class ShiftNode extends CoreMethodArrayArgumentsNode {
512512

513513
@Specialization(guards = "hash.empty()")
514-
protected Object shiftEmpty(RubyHash hash,
514+
protected Nil shiftEmpty(RubyHash hash,
515515
@Cached DispatchNode callDefault) {
516-
return callDefault.call(hash, "default", nil);
516+
return nil;
517517
}
518518

519519
@Specialization(guards = "!hash.empty()", limit = "hashStrategyLimit()")

test/mri/excludes/TestHash.rb

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,29 @@
11
exclude :test_ar2st, "mutating Hash during key.hash"
2-
exclude :test_ASET_fstring_key, "needs investigation"
3-
exclude :test_ASET_fstring_non_literal_key, "needs investigation"
4-
exclude :test_NEWHASH_fstring_key, "needs investigation"
5-
exclude :test_callcc_escape, "needs investigation"
6-
exclude :test_callcc_reenter, "needs investigation"
7-
exclude :test_create, "needs investigation"
8-
exclude :test_dup_equality, "needs investigation"
9-
exclude :test_dup_will_rehash, "needs investigation"
10-
exclude :test_fetch_error, "needs investigation"
11-
exclude :test_huge_iter_level, "needs investigation"
12-
exclude :test_inverse_hash, "needs investigation"
13-
exclude :test_recursive_hash_value_struct, "needs investigation"
14-
exclude :test_rehash2, "needs investigation"
15-
exclude :test_reject, "needs investigation"
16-
exclude :test_ruby2_keywords_hash?, "needs investigation"
17-
exclude :test_s_AREF, "needs investigation"
18-
exclude :test_callcc, "needs investigation"
19-
exclude :test_callcc_iter_level, "needs investigation"
20-
exclude :test_bug_12706, "needs investigation"
21-
exclude :test_to_proc, "needs investigation"
22-
exclude :test_transform_keys_bang, "needs investigation"
23-
exclude :test_AREF_fstring_key, "needs investigation"
24-
exclude :test_except, "needs investigation"
25-
exclude :test_transform_keys, "needs investigation"
2+
exclude :test_to_proc, "<true> expected but was"
3+
exclude :test_huge_iter_level, "RuntimeError expected but nothing was raised."
4+
exclude :test_merge!, "FrozenError expected but nothing was raised."
5+
exclude :test_create, "ArgumentError expected but nothing was raised."
6+
exclude :test_callcc_reenter, "[ruby-dev:47803] [Bug #9105]."
7+
exclude :test_select_reject_will_not_rehash, "<1> expected but was"
8+
exclude :test_reject_on_identhash, "<{}> expected but was"
269
exclude :test_select_on_identhash, "<{\"str\"=>1, \"str\"=>2}> expected but was"
2710
exclude :test_slice_on_identhash, "<{\"str\"=>1, \"str\"=>2}> expected but was"
28-
exclude :test_reject_on_identhash, "<{}> expected but was"
29-
exclude :test_select_reject_will_not_rehash, "<1> expected but was"
30-
exclude :test_merge!, "FrozenError expected but nothing was raised."
11+
exclude :test_shift2, "<:foo> expected but was"
12+
exclude :test_NEWHASH_fstring_key, "Expected \"ABC\" (oid=4680) to be the same as \"ABC\" (oid=48)."
13+
exclude :test_inverse_hash, "[ruby-core:34334]."
14+
exclude :test_rehash2, "RuntimeError expected but nothing was raised."
15+
exclude :test_shift_none, "<\"FOO\"> expected but was"
3116
exclude :test_update5, "FrozenError expected but nothing was raised."
3217
exclude :test_transform_values_on_identhash, "<{1=>2, 3=>4, 5=>6, \"str\"=>1, \"str\"=>2}> expected but was"
3318
exclude :test_s_AREF_from_pairs, "ArgumentError expected but nothing was raised."
3419
exclude :test_any_hash_fixable, "too slow"
20+
exclude :test_recursive_hash_value_struct, "[ruby-core:58567] [Bug #9151]."
21+
exclude :test_reject, "Expected 42 to be nil."
22+
exclude :test_transform_keys_bang, "<{false=>1, :b=>2, :c=>3}> expected but was"
23+
exclude :test_callcc_escape, "[ruby-dev:47803] [Bug #9105]."
24+
exclude :test_ASET_fstring_key, "Expected \"abc\" (oid=39832) to be the same as \"abc\" (oid=39848)."
25+
exclude :test_fetch_error, "Expected /\\.\\.\\.\\z/ to match \"key not found: \\\"gumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumby\\\"\"."
26+
exclude :test_ASET_fstring_non_literal_key, "Expected \"abc_def\" (oid=40568) to be the same as \"abc_def\" (oid=40584)."
27+
exclude :test_callcc, "RuntimeError: Continuations are unsupported on TruffleRuby"
28+
exclude :test_AREF_fstring_key, "NoMethodError: undefined method `count_objects' for ObjectSpace:Module"
29+
exclude :test_callcc_iter_level, "RuntimeError: Continuations are unsupported on TruffleRuby"
Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,29 @@
11
exclude :test_ar2st, "mutating Hash during key.hash"
2-
exclude :test_ASET_fstring_key, "needs investigation"
3-
exclude :test_ASET_fstring_non_literal_key, "needs investigation"
4-
exclude :test_NEWHASH_fstring_key, "needs investigation"
5-
exclude :test_callcc_escape, "needs investigation"
6-
exclude :test_callcc_reenter, "needs investigation"
7-
exclude :test_create, "needs investigation"
8-
exclude :test_dup_equality, "needs investigation"
9-
exclude :test_dup_will_rehash, "needs investigation"
10-
exclude :test_fetch_error, "needs investigation"
11-
exclude :test_huge_iter_level, "needs investigation"
12-
exclude :test_inverse_hash, "needs investigation"
13-
exclude :test_recursive_hash_value_struct, "needs investigation"
14-
exclude :test_rehash2, "needs investigation"
15-
exclude :test_reject, "needs investigation"
16-
exclude :test_ruby2_keywords_hash?, "needs investigation"
17-
exclude :test_s_AREF, "needs investigation"
18-
exclude :test_callcc, "needs investigation"
19-
exclude :test_callcc_iter_level, "needs investigation"
20-
exclude :test_bug_12706, "needs investigation"
21-
exclude :test_to_proc, "needs investigation"
22-
exclude :test_transform_keys_bang, "needs investigation"
23-
exclude :test_AREF_fstring_key, "needs investigation"
24-
exclude :test_except, "needs investigation"
25-
exclude :test_transform_keys, "needs investigation"
2+
exclude :test_to_proc, "<true> expected but was"
3+
exclude :test_huge_iter_level, "RuntimeError expected but nothing was raised."
4+
exclude :test_merge!, "FrozenError expected but nothing was raised."
5+
exclude :test_create, "ArgumentError expected but nothing was raised."
6+
exclude :test_callcc_reenter, "[ruby-dev:47803] [Bug #9105]."
7+
exclude :test_select_reject_will_not_rehash, "<1> expected but was"
8+
exclude :test_reject_on_identhash, "<{}> expected but was"
269
exclude :test_select_on_identhash, "<{\"str\"=>1, \"str\"=>2}> expected but was"
2710
exclude :test_slice_on_identhash, "<{\"str\"=>1, \"str\"=>2}> expected but was"
28-
exclude :test_reject_on_identhash, "<{}> expected but was"
29-
exclude :test_select_reject_will_not_rehash, "<1> expected but was"
30-
exclude :test_merge!, "FrozenError expected but nothing was raised."
11+
exclude :test_shift2, "<:foo> expected but was"
12+
exclude :test_NEWHASH_fstring_key, "Expected \"ABC\" (oid=44424) to be the same as \"ABC\" (oid=48)."
13+
exclude :test_inverse_hash, "[ruby-core:34334]."
14+
exclude :test_rehash2, "RuntimeError expected but nothing was raised."
15+
exclude :test_shift_none, "<\"FOO\"> expected but was"
3116
exclude :test_update5, "FrozenError expected but nothing was raised."
3217
exclude :test_transform_values_on_identhash, "<{1=>2, 3=>4, 5=>6, \"str\"=>1, \"str\"=>2}> expected but was"
3318
exclude :test_s_AREF_from_pairs, "ArgumentError expected but nothing was raised."
3419
exclude :test_any_hash_fixable, "too slow"
20+
exclude :test_recursive_hash_value_struct, "[ruby-core:58567] [Bug #9151]."
21+
exclude :test_reject, "Expected {1=>\"one\", 2=>false, true=>\"true\", \"cat\"=>99} to be an instance of Hash, not TestHash::TestSubHash::SubHash."
22+
exclude :test_transform_keys_bang, "<{false=>1, :b=>2, :c=>3}> expected but was"
23+
exclude :test_callcc_escape, "[ruby-dev:47803] [Bug #9105]."
24+
exclude :test_ASET_fstring_key, "Expected \"abc\" (oid=84584) to be the same as \"abc\" (oid=84600)."
25+
exclude :test_fetch_error, "Expected /\\.\\.\\.\\z/ to match \"key not found: \\\"gumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumbygumby\\\"\"."
26+
exclude :test_ASET_fstring_non_literal_key, "Expected \"abc_def\" (oid=85320) to be the same as \"abc_def\" (oid=85336)."
27+
exclude :test_callcc, "RuntimeError: Continuations are unsupported on TruffleRuby"
28+
exclude :test_AREF_fstring_key, "NoMethodError: undefined method `count_objects' for ObjectSpace:Module"
29+
exclude :test_callcc_iter_level, "RuntimeError: Continuations are unsupported on TruffleRuby"

0 commit comments

Comments
 (0)