Project

General

Profile

Actions

Bug #20606

closed

Thread#thread_variable_get, Thread#thread_variable? and Thread#[] methods handle non-String/Symbol parameter values differently

Added by andrykonchin (Andrew Konchin) 4 months ago. Updated 4 months ago.

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

Description

The Thread#thread_variable_get, Thread#thread_variable? and Thread#[] methods handle the key parameter that is not a String or a Symbol in different way but I would expect them to be consistent and raise an exception.

When no thread-local variables were assigned to a thread the Thread#thread_variable_get and Thread#thread_variable? methods don't raise TypeError when argument is of incorrect type. But Thread#[] does raise TypeError exception:

t = Thread.new {}.join

puts t.thread_variable_get(123).inspect # nil
puts t.thread_variable?(123).inspect # false

t[123] # `[]': 123 is not a symbol nor a string (TypeError)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0