Project

General

Profile

Actions

Bug #21356

closed

Error when accessing local variable named "default" with Binding#local_variable_get

Added by richardboehme (Richard Böhme) 30 days ago. Updated 5 days ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.5.0dev (2025-05-21T06:12:18Z master f6cbf499bc) +PRISM [x86_64-linux]
[ruby-core:122215]

Description

On Ruby master when using Binding#local_variable_get with the name :default it raises the following error:

'Binding#local_variable_get': numbered parameter 'default' is not a local variable (NameError)

I saw that this error was introduced in #21049 but it seems like the check for whether the passed variable name is a numbered parameter does not work for the :default symbol.

I think this might be an off-by-one error in the rb_numparam_id_p function in proc.c, where instead of adding 9 (the maximum number of numbered parameters) to tNUMPARAM_1 we currently add 10 which then includes the id of default as well? Compiling with this change (see attached diff) fixed the issue but I'm not sure if it might break other things.


Files

patch.diff (384 Bytes) patch.diff richardboehme (Richard Böhme), 05/21/2025 08:30 AM
Actions #1

Updated by nobu (Nobuyoshi Nakada) 30 days ago

  • Backport changed from 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN to 3.2: REQUIRED, 3.3: REQUIRED, 3.4: REQUIRED

Updated by mame (Yusuke Endoh) 30 days ago

Good catch, you are correct. Thank you! https://github.com/ruby/ruby/pull/13396

Updated by mame (Yusuke Endoh) 17 days ago

  • Status changed from Open to Closed

Updated by nagachika (Tomoyuki Chikanaga) 5 days ago

  • Backport changed from 3.2: REQUIRED, 3.3: REQUIRED, 3.4: REQUIRED to 3.2: REQUIRED, 3.3: DONTNEED, 3.4: REQUIRED

The numbered parameter checks in Binding#local_variable_get was introduced at 993fd96ce6bb763e08207bb3d53824d5d46d07a4 ([Bug #20965], [Bug #21049]). The changeset was not backported into ruby_3_3. I decide to mark this ticket "DONTNEED" at least for ruby_3_3.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0