summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2023-09-30 13:30:08 +0900
committernagachika <nagachika@ruby-lang.org>2023-09-30 13:30:08 +0900
commite7ab923b880ac75862cf9c287ac8ecbcd8ed1a31 (patch)
tree22d13a37fc2dd2401f77bfaf2921231a48670c34
parentd30781db4de82a891712f359d7659c9fc98cb215 (diff)
merge revision(s) d4c720a91bc7bb9ff31810e1720acffb939f7a2f: [Backport #19845]
Fix support for dynamic keys. (#8273) * Skip RBS test. --- cont.c | 8 +++----- spec/ruby/core/fiber/storage_spec.rb | 14 ++++++++++++++ tool/rbs_skip_tests | 2 ++ 3 files changed, 19 insertions(+), 5 deletions(-)
-rw-r--r--cont.c8
-rw-r--r--spec/ruby/core/fiber/storage_spec.rb14
-rw-r--r--tool/rbs_skip_tests2
-rw-r--r--version.h2
4 files changed, 20 insertions, 6 deletions
diff --git a/cont.c b/cont.c
index a1cb1c8ba0..949da83c57 100644
--- a/cont.c
+++ b/cont.c
@@ -2095,7 +2095,7 @@ rb_fiber_storage_get(VALUE self)
static int
fiber_storage_validate_each(VALUE key, VALUE value, VALUE _argument)
{
- rb_check_id(&key);
+ Check_Type(key, T_SYMBOL);
return ST_CONTINUE;
}
@@ -2167,8 +2167,7 @@ rb_fiber_storage_set(VALUE self, VALUE value)
static VALUE
rb_fiber_storage_aref(VALUE class, VALUE key)
{
- ID id = rb_check_id(&key);
- if (!id) return Qnil;
+ Check_Type(key, T_SYMBOL);
VALUE storage = fiber_storage_get(fiber_current());
@@ -2190,8 +2189,7 @@ rb_fiber_storage_aref(VALUE class, VALUE key)
static VALUE
rb_fiber_storage_aset(VALUE class, VALUE key, VALUE value)
{
- ID id = rb_check_id(&key);
- if (!id) return Qnil;
+ Check_Type(key, T_SYMBOL);
VALUE storage = fiber_storage_get(fiber_current());
diff --git a/spec/ruby/core/fiber/storage_spec.rb b/spec/ruby/core/fiber/storage_spec.rb
index 98215ebd59..e2bf6da04c 100644
--- a/spec/ruby/core/fiber/storage_spec.rb
+++ b/spec/ruby/core/fiber/storage_spec.rb
@@ -73,6 +73,20 @@ describe "Fiber.[]" do
Fiber.new { Fiber[:life] }.resume.should be_nil
end
end
+
+ ruby_version_is "3.2.3" do
+ it "can use dynamically defined keys" do
+ key = :"#{self.class.name}#.#{self.object_id}"
+ Fiber.new { Fiber[key] = 42; Fiber[key] }.resume.should == 42
+ end
+
+ it "can't use invalid keys" do
+ invalid_keys = [Object.new, "Foo", 12]
+ invalid_keys.each do |key|
+ -> { Fiber[key] }.should raise_error(TypeError)
+ end
+ end
+ end
end
describe "Fiber.[]=" do
diff --git a/tool/rbs_skip_tests b/tool/rbs_skip_tests
index 071b3ac313..d1dc8a509d 100644
--- a/tool/rbs_skip_tests
+++ b/tool/rbs_skip_tests
@@ -2,6 +2,8 @@ test_collection_install(RBS::CliTest) running tests without Bundler
test_collection_install_frozen(RBS::CliTest) running tests without Bundler
test_collection_update(RBS::CliTest) running tests without Bundler
+test_aref(FiberSingletonTest) the method should not accept String keys
+
NetSingletonTest depending on external resources
NetInstanceTest depending on external resources
TestHTTPRequest depending on external resources
diff --git a/version.h b/version.h
index b1cf86767a..8abac9ceb0 100644
--- a/version.h
+++ b/version.h
@@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 2
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 119
+#define RUBY_PATCHLEVEL 120
#include "ruby/version.h"
#include "ruby/internal/abi.h"