diff --git a/lib/puppet/functions.rb b/lib/puppet/functions.rb index ebe67bc40ce..95419c38c42 100644 --- a/lib/puppet/functions.rb +++ b/lib/puppet/functions.rb @@ -328,6 +328,7 @@ def repeated_param(type, name) # @api public def required_repeated_param(type, name) internal_param(type, name) + raise ArgumentError, 'A required repeated parameter cannot be added after an optional parameter' if @min != @max @min += 1 @max = :default end diff --git a/spec/unit/functions4_spec.rb b/spec/unit/functions4_spec.rb index 376b9199260..4306be1ec91 100644 --- a/spec/unit/functions4_spec.rb +++ b/spec/unit/functions4_spec.rb @@ -240,6 +240,10 @@ def test(x) expect { create_function_with_rq_after_opt }.to raise_error(ArgumentError, 'A required parameter cannot be added after an optional parameter') end + it 'a function can not be created with required repeated parameters declared after optional ones' do + expect { create_function_with_rq_repeated_after_opt }.to raise_error(ArgumentError, 'A required repeated parameter cannot be added after an optional parameter') + end + it 'an error is raised with reference to multiple methods when called with mis-matched arguments' do f = create_min_function_class_disptaching_to_two_methods() # TODO: Bogus parameters, not yet used @@ -658,6 +662,18 @@ def t1(*x) end end + def create_function_with_rq_repeated_after_opt + f = Puppet::Functions.create_function('t1') do + dispatch :t1 do + optional_param 'Numeric', :x + required_repeated_param 'Numeric', :y + end + def t1(x, *y) + x + end + end + end + def create_function_with_param_after_repeated f = Puppet::Functions.create_function('t1') do dispatch :t1 do