summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2023-08-24 15:19:33 +1200
committerGitHub <noreply@github.com>2023-08-24 15:19:33 +1200
commitd4c720a91bc7bb9ff31810e1720acffb939f7a2f (patch)
tree164045fc674af9c849d76ab446cfd3caece7fee3
parentbd22bb259c183b91656bea72899fe91c31aeb44e (diff)
Fix support for dynamic keys. (#8273)
* Skip RBS test.
Notes
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
-rw-r--r--cont.c8
-rw-r--r--spec/ruby/core/fiber/storage_spec.rb14
-rw-r--r--tool/rbs_skip_tests2
3 files changed, 19 insertions, 5 deletions
diff --git a/cont.c b/cont.c
index ac3d77f940..db8508e724 100644
--- a/cont.c
+++ b/cont.c
@@ -2118,7 +2118,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;
}
@@ -2190,8 +2190,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(), FALSE);
if (storage == Qnil) return Qnil;
@@ -2212,8 +2211,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(), value != Qnil);
if (storage == Qnil) return Qnil;
diff --git a/spec/ruby/core/fiber/storage_spec.rb b/spec/ruby/core/fiber/storage_spec.rb
index e99fe6e4df..e5232c8894 100644
--- a/spec/ruby/core/fiber/storage_spec.rb
+++ b/spec/ruby/core/fiber/storage_spec.rb
@@ -74,6 +74,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 6adef0059b..aefdb23a79 100644
--- a/tool/rbs_skip_tests
+++ b/tool/rbs_skip_tests
@@ -25,6 +25,8 @@ test_subtract(RBS::CliTest) running tests without Bundler
test_subtract_several_subtrahends(RBS::CliTest) running tests without Bundler
test_subtract_write(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