Project

General

Profile

Actions

Bug #16640

closed

Symbol#to_proc reports -1 for arity

Added by kddnewton (Kevin Newton) about 4 years ago. Updated about 4 years ago.

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

Description

When you create a proc using Symbol#to_proc syntax, it reports the arity as -1, even though the required number of arguments is actually 1. This can happen based on lambda(&:hash), proc(&:hash), or some_method(&:hash). Opened a PR with a fix here: https://github.com/ruby/ruby/pull/2913.

Updated by kddnewton (Kevin Newton) about 4 years ago

Ooo just found https://bugs.ruby-lang.org/issues/9520. I kind of get the argument to keep it consistent with other procs, but this is still a special case within block types, and it will fail if you call it without an argument.

Updated by kddnewton (Kevin Newton) about 4 years ago

To add some context, this came up because of https://github.com/rails/rails/pull/38474 - specifically https://github.com/rails/rails/blob/2fa1f7c48151617e13b4ad6ca065e47c8d7b42d0/activesupport/lib/active_support/callbacks.rb#L460-L461. The idea being that it's checking the arity to determine what kind of callback to build, but because Symbol#to_proc says it's -1, it actually results in an error.

Actions #3

Updated by kddnewton (Kevin Newton) about 4 years ago

  • Subject changed from Symbol#to_proc has incorrect arity to Symbol#to_proc reports -1 for arity

Updated by zverok (Victor Shepelev) about 4 years ago

#9250 was closed with the reason

The proc created by Symbol#to_proc is not a lambda, but a proc

But in #16260, it was discussed that Symbol#to_proc behaves more like lambda, and so hopefully all of its introspection methods (#lambda?, #arity, #parameters) will be fixed.

Updated by kddnewton (Kevin Newton) about 4 years ago

Actually this can be closed, as it doesn't make sense for arity > 1.

Actions #7

Updated by nobu (Nobuyoshi Nakada) about 4 years ago

  • Description updated (diff)
  • Status changed from Open to Rejected

Updated by Eregon (Benoit Daloze) about 4 years ago

The arity should actually be -2 which means 1 required arguments + any number of optional arguments.

Actions #9

Updated by nobu (Nobuyoshi Nakada) about 4 years ago

  • Status changed from Rejected to Open
Actions #10

Updated by nobu (Nobuyoshi Nakada) about 4 years ago

  • Status changed from Open to Closed

Applied in changeset git|5b29ea0845c14092abd866ce0183c52635bade4c.


Proc from Symbol needs a receiver

So its arity should be -2 instead of -1.

[Bug #16640]
https://bugs.ruby-lang.org/issues/16640#change-84337

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0