Skip to content

Commit

Permalink
Merge pull request #3855 from thallgren/no_required_repeated_after_op…
Browse files Browse the repository at this point in the history
…tional

(PUP-4438) Ensure that required_repeated_param cannot follow optionals
  • Loading branch information
hlindberg committed Apr 21, 2015
2 parents c55b69a + feaf07c commit 5badbff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/puppet/functions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions spec/unit/functions4_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5badbff

Please sign in to comment.