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) about 2 months ago. Updated about 8 hours 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) about 2 months 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 nagachika (Tomoyuki Chikanaga) about 1 month 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.

Updated by k0kubun (Takashi Kokubun) about 8 hours ago

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

Same here; the behavior was added in Ruby 3.5 and we don't even have the modified function in Ruby 3.4. I mark it "DONTNEED" for ruby_3_4 as well.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0