Project

General

Profile

Actions

Bug #10831

closed

Variable keyword arguments shouldn't create immortal symbols

Added by marcandre (Marc-Andre Lafortune) about 9 years ago. Updated about 9 years ago.

Status:
Closed
Target version:
-
[ruby-core:68031]

Description

Calling a method with keyword arguments will, sometimes, create immortal symbols.

The following tests should not fail:

def test_kwarg_symbol_leak_no_rest
  foo = -> (arg: 42) {}
  assert_no_immortal_symbol_created("kwarg no rest") do |name|
    assert_raise(ArgumentError) { foo.call(name.to_sym => 42) }
  end
end

def test_kwarg_symbol_leak_with_rest
  foo = -> (arg: 2, **options) {}
  assert_no_immortal_symbol_created("kwarg with rest") do |name|
    foo.call(name.to_sym => 42)
  end
end

def test_kwarg_symbol_leak_just_rest
  foo = -> (**options) {}
  assert_no_immortal_symbol_created("kwarg just rest") do |name|
    foo.call(name.to_sym => 42)
  end
end

Note: the last one succeeds (because the hash is simply cloned internally), and is there for completeness.

Actions

Also available in: Atom PDF

Like0
Like0Like0