Project

General

Profile

Actions

Bug #20974

closed

Required and optional anonymous parameter show differently in Proc#parameters

Added by alanwu (Alan Wu) 10 months ago. Updated 9 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:120350]

Description

The following has had the same output since Ruby 1.9, when Proc#parameters was introduced:

p(proc   { |(_a)| }.parameters) # => [[:opt, nil]]
p(lambda { |(_a)| }.parameters) # => [[:req]]

I think they should be [[:opt]] and [[:req]] or [[:opt, nil]] and [[:req, nil]]. I prefer the nil-free option since that feels more anonymous.


Related issues 1 (0 open1 closed)

Related to Ruby - Bug #20955: Subtle differences with Proc#parameters for anonymous parametersClosedActions
Actions #1

Updated by alanwu (Alan Wu) 10 months ago

  • Related to Bug #20955: Subtle differences with Proc#parameters for anonymous parameters added
Actions #2

Updated by alanwu (Alan Wu) 10 months ago

  • Description updated (diff)

Updated by alanwu (Alan Wu) 10 months ago

It's not hard to patch this small issue. We need consensus on whether this is an issue and what the new behavior should be, though.

diff --git a/iseq.c b/iseq.c
index 639ca3a4cd..d5808b81a5 100644
--- a/iseq.c
+++ b/iseq.c
@@ -3606,7 +3606,9 @@ rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc)
     if (is_proc) {
         for (i = 0; i < body->param.lead_num; i++) {
             PARAM_TYPE(opt);
-            rb_ary_push(a, rb_id2str(PARAM_ID(i)) ? ID2SYM(PARAM_ID(i)) : Qnil);
+            if (rb_id2str(PARAM_ID(i))) {
+                rb_ary_push(a, ID2SYM(PARAM_ID(i)));
+            }
             rb_ary_push(args, a);
         }
     }

Updated by mame (Yusuke Endoh) 9 months ago

Discussed at the dev meeting. @matz (Yukihiro Matsumoto) said that it should return [[:opt]] instead of [[:opt, nil]].

Actions #5

Updated by alanwu (Alan Wu) 9 months ago

  • Status changed from Open to Closed

Applied in changeset git|6637aa4682ef64134e05af949a9beee260dab937.


Proc#parameters: Show anonymous optionals as [:opt]

Have this for lead parameters as well as parameters after rest ("post").

[Bug #20974]

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0