puppetlabs/puppet · error · ArgumentError
The type '%{type}' does not represent a valid set of paramet
Error message
The type '%{type}' does not represent a valid set of parameters for %{subject}.new() What it means
When Init[T] carries init args, its constructor computation requires that some overload of T.new() accepts the first value plus those init args (count within the tuple's size range and the trailing parameter types assignable). If no overload of the target type's new function qualifies, this ArgumentError reports the full Init type and T.new() as the mismatch.
Source
Thrown at lib/puppet/pops/types/p_init_type.rb:187
single_tuples, other_tuples = param_tuples.partition { |tuple| EXACTLY_ONE == tuple.size_range }
single_types.concat(single_tuples.map { |tuple| tuple.types[0] })
else
tc = TypeCalculator.singleton
init_arg_types = @init_args.map { |arg| tc.infer_set(arg) }
arg_count = 1 + init_arg_types.size
# disqualify all parameter tuples that doesn't allow one value (type unknown at ths stage) + init args.
param_tuples = param_tuples.select do |tuple|
min, max = tuple.size_range
if arg_count >= min && arg_count <= max
# Aside from the first parameter, does the other parameters match?
tuple.assignable?(PTupleType.new(tuple.types[0..0].concat(init_arg_types)))
else
false
end
end
if param_tuples.empty?
raise ArgumentError, _("The type '%{type}' does not represent a valid set of parameters for %{subject}.new()") %
{ type: to_s, subject: @type.generalize.name }
end
single_types.concat(param_tuples.map { |tuple| tuple.types[0] })
other_tuples = EMPTY_ARRAY
end
@single_type = PVariantType.maybe_create(single_types)
unless other_tuples.empty?
@other_type = PVariantType.maybe_create(other_tuples)
@has_optional_single = other_tuples.any? { |tuple| tuple.size_range.min == 1 }
end
guard = RecursionGuard.new
accept(NoopTypeAcceptor::INSTANCE, guard)
@self_recursion = guard.recursive_this?(self)
end
def accept(visitor, guard)
guarded_recursion(guard, nil) do |g|View on GitHub (pinned to e227c27540)
Solutions
- Check the target type's constructor overloads (the new_function definitions in lib/puppet/pops/types/types.rb) and make the init args match one signature's count and types.
- For collection sizing/typing use the type parameters directly — Array[Integer, 3] — instead of Init[Array, 3].
- Drop the init args entirely when a plain Init[T] suffices: Init[T].new(value) accepts any value assignable to T.
Example fix
# before $t = Init[Array[Integer], 'x'] # after $t = Init[Array[Integer], 3]
Defensive patterns
Strategy: try-catch
Validate before calling
# Puppet — prefer parameterized collection types over Init with args # use Array[Integer, 3] / Hash[String, Integer] instead of Init[Array, 3] when the goal is element/size typing
Type guard
def init_args_match?(target_type, args)
sigs = target_type.new_function.dispatcher.signatures.map { |c| c.type.param_types }
types = args.map { |a| Puppet::Pops::Types::TypeCalculator.singleton.infer(a) }
sigs.any? { |t| min, max = t.size_range; args.size + 1 >= min && args.size + 1 <= max &&
t.assignable?(Puppet::Pops::Types::PTupleType.new(t.types[0..0].concat(types))) }
end Try / catch
begin
result = Init[Array[Integer], 3].new(*values)
rescue ArgumentError => e
fail("Init args do not match any Array.new overload: #{e.message}")
end Prevention
- Read the target type's new_function overloads before adding init args to Init.
- Treat Init's extra parameters as constructor arguments (T.new(first, *args)), not element constraints.
When it happens
Trigger: Init args that fit no overload of the target's new function, e.g. Init[Array[Integer], 'x'] (Array#new accepts an Integer size or another Array, not a String) or wrong-arity cases like Init[Array[Integer], 2, 3].new(...) where Tuple[...] matching fails.
Common situations: Assuming Init's extra parameters are element/size constraints on the collection (they are constructor arguments forwarded to T.new); porting Ruby initialization idioms whose overloads differ from Puppet's new_function dispatchers; adding args after changing the target type.
Related errors
- Init cannot be parameterized with an undefined type and addi
- Creation of new instance of type '%{type_name}' is not suppo
- Only Runtime type 'ruby' is supported, got #{type.runtime}
- Data Type Load Error for type '%{type_name}': %{message}
- a data type must have an interface
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/44326b1777e3a504.
Report an issue: GitHub.