diff --git a/lib/puppet/functions.rb b/lib/puppet/functions.rb index 74a5d55bf21..3924effc1a5 100644 --- a/lib/puppet/functions.rb +++ b/lib/puppet/functions.rb @@ -345,6 +345,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 1d80f92c385..008aa9fd591 100644 --- a/spec/unit/functions4_spec.rb +++ b/spec/unit/functions4_spec.rb @@ -240,6 +240,10 @@ def min(x,y) 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 @@ -668,6 +672,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