Actions
Bug #12884
closedUsing a HashWithIndifferentAccess with a default value in a function with a keyword parameter converts it to a Hash.
Description
A strange bug that broke our production when migrating from 2.1.9 to 2.2.5 (still present in 2.3.1)
It involves HashWithIndifferentAccess from active support. The version used is 3.2.22.4 (against all ruby versions)
Here's a bit of code to reproduce it :
def test(params = HashWithIndifferentAccess.new, disrupter: nil)
params.class
end
x = HashWithIndifferentAccess.new
x[:foo] = 'bar'
test x
# 2.3.1 => Hash
# 2.2.5 => Hash
# 2.1.9 => HashWithIndifferentAccess
But this only happens if there is a keyword parameter AND a default value for your HashWithIndifferentAccess parameter :
Not using a keyword parameter doesn't change the type
def test(params = HashWithIndifferentAccess.new, disrupter = nil)
params.class
end
x = HashWithIndifferentAccess.new
x[:foo] = 'bar'
test x
# 2.3.1 => HashWithIndifferentAccess
# 2.2.5 => HashWithIndifferentAccess
# 2.1.9 => HashWithIndifferentAccess
Not using a default value don't change the type
def test(params, disrupter: nil)
params.class
end
x = HashWithIndifferentAccess.new
x[:foo] = 'bar'
test x
# 2.3.1 => HashWithIndifferentAccess
# 2.2.5 => HashWithIndifferentAccess
# 2.1.9 => HashWithIndifferentAccess
Actions
Like0
Like0Like0Like0Like0Like0Like0