diff options
| author | dearblue <[email protected]> | 2021-11-24 23:34:31 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-11-26 12:18:41 +0900 |
| commit | 668b12e7566282f6c0165252e2b2f5432964020a (patch) | |
| tree | e8d2cd84b26ed6980f3c83b5ee7a2ef83225083b /mrbgems/mruby-method/src | |
| parent | b631c226eb3e59a813224183bbc9ddc2a01acd0e (diff) | |
| download | mruby-668b12e7566282f6c0165252e2b2f5432964020a.tar.gz mruby-668b12e7566282f6c0165252e2b2f5432964020a.zip | |
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`.
Diffstat (limited to 'mrbgems/mruby-method/src')
| -rw-r--r-- | mrbgems/mruby-method/src/method.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/mrbgems/mruby-method/src/method.c b/mrbgems/mruby-method/src/method.c index b8a55e618..18fcaa03a 100644 --- a/mrbgems/mruby-method/src/method.c +++ b/mrbgems/mruby-method/src/method.c @@ -300,7 +300,12 @@ method_search_vm(mrb_state *mrb, struct RClass **cp, mrb_sym mid) return NULL; if (MRB_METHOD_PROC_P(m)) return MRB_METHOD_PROC(m); - return mrb_proc_new_cfunc(mrb, MRB_METHOD_FUNC(m)); + + struct RProc *proc = mrb_proc_new_cfunc(mrb, MRB_METHOD_FUNC(m)); + if (MRB_METHOD_NOARG_P(m)) { + proc->flags |= MRB_PROC_NOARG; + } + return proc; } static mrb_value |
