Project

General

Profile

Bug #14373

Methods with more than 32 keyword arguments with default values have some of the arguments set to default despite being passed in.

Added by sk (SK Liew) 11 months ago. Updated 11 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux], ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]
[ruby-core:84921]

Description

class Test
  #  33 keyword arguments
  def test1(a0: '', a1: '', a2: '', a3: '', a4: '', a5: '', a6: '', a7: '', a8: '', b0: '', b1: '', b2: '', b3: '', b4: '', b5: '', b6: '', b7: '', b8: '', c0: '', c1: '', c2: '', c3: '', c4: '', c5: '', c6: '', c7: '', c8: '', d0: '', d1: '', d2: '', d3: '', d4: '', d5: '')
    puts a1
    puts d5
    puts '-------'
  end
  #  32 keyword arguments
  def test2(a0: '', a1: '', a2: '', a3: '', a4: '', a5: '', a6: '', a7: '', a8: '', b0: '', b1: '', b2: '', b3: '', b4: '', b5: '', b6: '', b7: '', b8: '', c0: '', c1: '', c2: '', c3: '', c4: '', c5: '', c6: '', c7: '', c8: '', d0: '', d1: '', d2: '', d3: '', d4: '')
    puts a1
    puts d4
    puts '-------'
  end
end
puts 'Test1 with a1, expects a1, prints nothing in 2.5, prints a1 in 2.4 and 2.3'
Test.new.test1(a1: 'a1')

puts 'Test1 with a1 and d5, expects a1 and d5 but only prints a1'
Test.new.test1(a1: 'a1', d5: 'd5')

puts 'Test1 with d5, expects d5 but prints nothing'
Test.new.test1({d5: 'd5'})

puts 'Test2 with a1 and d4, as expected'
Test.new.test2(a1: 'a1', d4: 'd4')

puts 'Test2 with a1, as expected'
Test.new.test2(a1: 'a1')

The code above describes the issues. I noticed that Ruby 2.5 behaves slightly differently from 2.3 and 2.4 (as described in the first test case).

Associated revisions

Revision fb839332
Added by nobu (Nobuyoshi Nakada) 11 months ago

vm_insnhelper.c: fix many keyword arguments

  • vm_insnhelper.c (vm_check_keyword): if the index exceeds the width of unspecified bits, that argument is specified. unspecified_bits still be a fixnum if the actual arguments do not exceed the limit, regardless the formal parameters size. [Bug #14373]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61940 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 61940
Added by nobu (Nobuyoshi Nakada) 11 months ago

vm_insnhelper.c: fix many keyword arguments

  • vm_insnhelper.c (vm_check_keyword): if the index exceeds the width of unspecified bits, that argument is specified. unspecified_bits still be a fixnum if the actual arguments do not exceed the limit, regardless the formal parameters size. [Bug #14373]

Revision 12c0cc01
Added by nobu (Nobuyoshi Nakada) 11 months ago

vm_args.c: fix KW_SPECIFIED_BITS_MAX

  • vm_args.c (KW_SPECIFIED_BITS_MAX): subtracted 1bit for
    FIXNUM_FLAG. [Bug #14373]

  • vm_insnhelper.c (vm_check_keyword): unsigned for bit operation.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61945 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 61945
Added by nobu (Nobuyoshi Nakada) 11 months ago

vm_args.c: fix KW_SPECIFIED_BITS_MAX

  • vm_args.c (KW_SPECIFIED_BITS_MAX): subtracted 1bit for
    FIXNUM_FLAG. [Bug #14373]

  • vm_insnhelper.c (vm_check_keyword): unsigned for bit operation.

History

#1 [ruby-core:84922] Updated by shevegen (Robert A. Heiler) 11 months ago

I ran the code and indeed, this is very strange behaviour.

The bigget surprise to me was the "prints nothing in 2.5, prints
a1 in 2.4 and 2.3" part. I know way too little to say anything
but to me this looks like a bug/regression.

I guess your code example could be used for new tests to ensure
that the functionality does not disappear in new ruby releases,
if it is a bug that is. :) (I just can't think of a reason why
it would work on ruby 2.4 but not 2.5)

#2 Updated by nobu (Nobuyoshi Nakada) 11 months ago

  • Status changed from Open to Closed

Applied in changeset trunk|r61940.


vm_insnhelper.c: fix many keyword arguments

  • vm_insnhelper.c (vm_check_keyword): if the index exceeds the width of unspecified bits, that argument is specified. unspecified_bits still be a fixnum if the actual arguments do not exceed the limit, regardless the formal parameters size. [Bug #14373]

Also available in: Atom PDF