diff --git a/lib/puppet/functions.rb b/lib/puppet/functions.rb index a15e166f66e..c29dfc24929 100644 --- a/lib/puppet/functions.rb +++ b/lib/puppet/functions.rb @@ -208,7 +208,7 @@ def self.min_max_param(method) end # Construct a signature consisting of Object type, with min, and max, and given names. - # (there is only one type entry). Note that this signature is Object, not Optional[Object]. + # (there is only one type entry). # # @api private def self.object_signature(from, to, names) diff --git a/lib/puppet/functions/assert_type.rb b/lib/puppet/functions/assert_type.rb index 7ff216a5e70..ccd42c2999f 100644 --- a/lib/puppet/functions/assert_type.rb +++ b/lib/puppet/functions/assert_type.rb @@ -17,18 +17,18 @@ Puppet::Functions.create_function(:assert_type) do dispatch :assert_type do param 'Type', 'type' - param 'Optional[Object]', 'value' - optional_block_param 'Callable[Optional[Object],Optional[Object]]', 'block' + param 'Object', 'value' + optional_block_param 'Callable[Object, Object]', 'block' end dispatch :assert_type_s do param 'String', 'type_string' - param 'Optional[Object]', 'value' - optional_block_param 'Callable[Optional[Object], Optional[Object]]', 'block' + param 'Object', 'value' + optional_block_param 'Callable[Object, Object]', 'block' end # @param type [Type] the type the value must be an instance of - # @param value [Optional[Object]] the value to assert + # @param value [Object] the value to assert # def assert_type(type, value, block=nil) unless Puppet::Pops::Types::TypeCalculator.instance?(type,value) @@ -47,7 +47,7 @@ def assert_type(type, value, block=nil) end # @param type_string [String] the type the value must be an instance of given in String form - # @param value [Optional[Object]] the value to assert + # @param value [Object] the value to assert # def assert_type_s(type_string, value) t = Puppet::Pops::Types::TypeParser.new.parse(type_string) diff --git a/lib/puppet/pops/evaluator/closure.rb b/lib/puppet/pops/evaluator/closure.rb index 30c5363000b..7a616252834 100644 --- a/lib/puppet/pops/evaluator/closure.rb +++ b/lib/puppet/pops/evaluator/closure.rb @@ -167,7 +167,7 @@ def create_callable_type() type = if param.type_expr @evaluator.evaluate(param.type_expr, @enclosing_scope) else - Puppet::Pops::Types::TypeFactory.optional_object() + Puppet::Pops::Types::TypeFactory.object() end if param.captures_rest && type.is_a?(Puppet::Pops::Types::PArrayType) diff --git a/lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb b/lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb index 589b05c054f..1f7abacefd0 100644 --- a/lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb +++ b/lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb @@ -98,7 +98,6 @@ def self.legacy_newfunction(name, options, &block) # Define a dispatch that performs argument type/count checking # dispatch :__relay__call__ do - # Use Puppet Type Object (not Optional[Object] since the 3x API passes undef as empty string). param 'Object', 'args' # Specify arg count (transformed from 3x function arity specification). arg_count(min_arg_count, max_arg_count) diff --git a/lib/puppet/pops/loader/static_loader.rb b/lib/puppet/pops/loader/static_loader.rb index 27cfbe4627a..336d33e919d 100644 --- a/lib/puppet/pops/loader/static_loader.rb +++ b/lib/puppet/pops/loader/static_loader.rb @@ -49,7 +49,7 @@ def create_logging_functions() # Logs per the specified level, outputs formatted information for arrays, hashes etc. # Overrides the implementation in Function that uses dispatching. This is not needed here - # since it accepts 0-n Optional[Object] + # since it accepts 0-n Object. # define_method(:call) do |scope, *vals| # NOTE: 3x, does this: vals.join(" ") diff --git a/lib/puppet/pops/types/type_factory.rb b/lib/puppet/pops/types/type_factory.rb index e01494f8fa5..916a8e73b76 100644 --- a/lib/puppet/pops/types/type_factory.rb +++ b/lib/puppet/pops/types/type_factory.rb @@ -70,11 +70,6 @@ def self.optional(optional_type = nil) t end - # Convenience method to produce an Optional[Object] type - def self.optional_object() - optional(object()) - end - # Produces the Enum type, optionally with specific string values # @api public # @@ -203,7 +198,7 @@ def self.all_callables() # A min < params.size means that the difference are optional. # If max > params.size means that the last type repeats. # if max is :default, the max value is unbound (infinity). - # + # # Params are given as a sequence of arguments to {#type_of}. # def self.callable(*params) diff --git a/spec/integration/parser/future_compiler_spec.rb b/spec/integration/parser/future_compiler_spec.rb index e381101c79e..57205ceafca 100644 --- a/spec/integration/parser/future_compiler_spec.rb +++ b/spec/integration/parser/future_compiler_spec.rb @@ -563,7 +563,7 @@ class { 'foo': x => Bar[joke] } compile_to_catalog(<<-MANIFEST) with(1) |$x, String $defaulted = 1| { notify { "${$x + $defaulted}": }} MANIFEST - end.to raise_error(/expected.*Optional.*String.*actual.*Integer.*Integer/m) + end.to raise_error(/expected.*Object.*String.*actual.*Integer.*Integer/m) end it 'raises an error when a default argument value is an incorrect type and there are no arguments passed' do diff --git a/spec/unit/functions/assert_type_spec.rb b/spec/unit/functions/assert_type_spec.rb index 612d33d9d21..4c13db64bdd 100644 --- a/spec/unit/functions/assert_type_spec.rb +++ b/spec/unit/functions/assert_type_spec.rb @@ -37,8 +37,8 @@ end.to raise_error(ArgumentError, Regexp.new(Regexp.escape( "function 'assert_type' called with mis-matched arguments expected one of: - assert_type(Type type, Optional[Object] value, Callable[Optional[Object], Optional[Object]] block {0,1}) - arg count {2,3} - assert_type(String type_string, Optional[Object] value, Callable[Optional[Object], Optional[Object]] block {0,1}) - arg count {2,3} + assert_type(Type type, Object value, Callable[Object, Object] block {0,1}) - arg count {2,3} + assert_type(String type_string, Object value, Callable[Object, Object] block {0,1}) - arg count {2,3} actual: assert_type(Integer, Integer) - arg count {2}"))) end diff --git a/spec/unit/pops/evaluator/evaluating_parser_spec.rb b/spec/unit/pops/evaluator/evaluating_parser_spec.rb index 0580945c786..8477aa0f2e3 100644 --- a/spec/unit/pops/evaluator/evaluating_parser_spec.rb +++ b/spec/unit/pops/evaluator/evaluating_parser_spec.rb @@ -893,7 +893,7 @@ def test(count, block) env_loader = Puppet.lookup(:loaders).public_environment_loader fc = Puppet::Functions.create_function(:test) do dispatch :test do - param 'Optional[Object]', 'lambda_arg' + param 'Object', 'lambda_arg' required_block_param end def test(lambda_arg, block) diff --git a/spec/unit/pops/types/type_calculator_spec.rb b/spec/unit/pops/types/type_calculator_spec.rb index 37947578ffc..f2e7e6800c9 100644 --- a/spec/unit/pops/types/type_calculator_spec.rb +++ b/spec/unit/pops/types/type_calculator_spec.rb @@ -78,8 +78,8 @@ def struct_t(type_hash) Puppet::Pops::Types::TypeFactory.struct(type_hash) end - def optional_object_t - Puppet::Pops::Types::TypeFactory.optional_object() + def object_t + Puppet::Pops::Types::TypeFactory.object() end def types @@ -1148,10 +1148,8 @@ class Bar < Foo the_block = factory.LAMBDA(params,factory.literal(42)) the_closure = Puppet::Pops::Evaluator::Closure.new(:fake_evaluator, the_block, :fake_scope) expect(calculator.instance?(all_callables_t, the_closure)).to be_true - # TODO: lambdas are currently unttypes, anything can be given if arg count is correct - expect(calculator.instance?(callable_t(optional_object_t), the_closure)).to be_true - # Arg count is wrong - expect(calculator.instance?(callable_t(optional_object_t, optional_object_t), the_closure)).to be_false + expect(calculator.instance?(callable_t(object_t), the_closure)).to be_true + expect(calculator.instance?(callable_t(object_t, object_t), the_closure)).to be_false end it 'a Function instance should be considered a Callable' do