From 668b12e7566282f6c0165252e2b2f5432964020a Mon Sep 17 00:00:00 2001 From: dearblue Date: Wed, 24 Nov 2021 23:34:31 +0900 Subject: Check more `MRB_ARGS_NONE()` The `__id__` method implemented in the C function has `MRB_ARGS_NONE()` specified, but it is also effective in the following cases. ```ruby p nil.__id__ opts: 1 rescue p :a p nil.method(:__id__).call 1 rescue p :b p nil.method(:__id__).call opts: 1 rescue p :c p nil.method(:__id__).to_proc.call 1 rescue p :d p nil.method(:__id__).to_proc.call opts: 1 rescue p :e p nil.method(:__id__).unbind.bind_call nil, 1 rescue p :f p nil.method(:__id__).unbind.bind_call nil, opts: 1 rescue p :g p nil.__send__ :__id__, 1 rescue p :h p nil.__send__ :__id__, opts: 1 rescue p :i ``` After applying this patch, all items will output symbols in the same way as CRuby. For this purpose, add `MRB_PROC_NOARG` to `struct RProc::flags`. --- test/t/argumenterror.rb | 5 +++++ test/t/kernel.rb | 3 +++ 2 files changed, 8 insertions(+) (limited to 'test') diff --git a/test/t/argumenterror.rb b/test/t/argumenterror.rb index 3dcb29a4b..3772f1b0f 100644 --- a/test/t/argumenterror.rb +++ b/test/t/argumenterror.rb @@ -30,3 +30,8 @@ assert("'wrong number of arguments' from mrb_get_args") do assert_argnum_error(1, 2){Object.const_set(:B)} assert_argnum_error(3, 2){Object.const_set(:C, 1, 2)} end + +assert('Call to MRB_ARGS_NONE method') do + assert_raise(ArgumentError) { nil.__id__ 1 } + assert_raise(ArgumentError) { nil.__id__ opts: 1 } +end diff --git a/test/t/kernel.rb b/test/t/kernel.rb index 0a70ec0d2..06551ae88 100644 --- a/test/t/kernel.rb +++ b/test/t/kernel.rb @@ -95,6 +95,9 @@ assert('Kernel#__send__', '15.3.1.3.4') do args = [:respond_to?, :nil?] assert_true __send__(*args) assert_equal [:respond_to?, :nil?], args + + assert_raise(ArgumentError) { nil.__send__(:__id__, 1) } + assert_raise(ArgumentError) { nil.__send__(:__id__, opts: 1) } end assert('Kernel#block_given?', '15.3.1.3.6') do -- cgit v1.2.3