{"record":{"id":"44326b1777e3a504","repo":"puppetlabs/puppet","slug":"the-type-type-does-not-represent-a-valid-set","errorCode":null,"errorMessage":"The type '%{type}' does not represent a valid set of parameters for %{subject}.new()","messagePattern":"The type '%(.+?)' does not represent a valid set of parameters for %(.+?)\\.new\\(\\)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/types/p_init_type.rb","lineNumber":187,"sourceCode":"      single_tuples, other_tuples = param_tuples.partition { |tuple| EXACTLY_ONE == tuple.size_range }\n      single_types.concat(single_tuples.map { |tuple| tuple.types[0] })\n    else\n      tc = TypeCalculator.singleton\n      init_arg_types = @init_args.map { |arg| tc.infer_set(arg) }\n      arg_count = 1 + init_arg_types.size\n\n      # disqualify all parameter tuples that doesn't allow one value (type unknown at ths stage) + init args.\n      param_tuples = param_tuples.select do |tuple|\n        min, max = tuple.size_range\n        if arg_count >= min && arg_count <= max\n          # Aside from the first parameter, does the other parameters match?\n          tuple.assignable?(PTupleType.new(tuple.types[0..0].concat(init_arg_types)))\n        else\n          false\n        end\n      end\n      if param_tuples.empty?\n        raise ArgumentError, _(\"The type '%{type}' does not represent a valid set of parameters for %{subject}.new()\") %\n                             { type: to_s, subject: @type.generalize.name }\n      end\n      single_types.concat(param_tuples.map { |tuple| tuple.types[0] })\n      other_tuples = EMPTY_ARRAY\n    end\n    @single_type = PVariantType.maybe_create(single_types)\n    unless other_tuples.empty?\n      @other_type = PVariantType.maybe_create(other_tuples)\n      @has_optional_single = other_tuples.any? { |tuple| tuple.size_range.min == 1 }\n    end\n\n    guard = RecursionGuard.new\n    accept(NoopTypeAcceptor::INSTANCE, guard)\n    @self_recursion = guard.recursive_this?(self)\n  end\n\n  def accept(visitor, guard)\n    guarded_recursion(guard, nil) do |g|","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/types/p_init_type.rb#L169-L205","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\n$t = Init[Array[Integer], 'x']\n\n# after\n$t = Init[Array[Integer], 3]","handlingStrategy":"try-catch","validationCode":"# Puppet — prefer parameterized collection types over Init with args\n# use Array[Integer, 3] / Hash[String, Integer] instead of Init[Array, 3] when the goal is element/size typing","typeGuard":"def init_args_match?(target_type, args)\n  sigs = target_type.new_function.dispatcher.signatures.map { |c| c.type.param_types }\n  types = args.map { |a| Puppet::Pops::Types::TypeCalculator.singleton.infer(a) }\n  sigs.any? { |t| min, max = t.size_range; args.size + 1 >= min && args.size + 1 <= max &&\n    t.assignable?(Puppet::Pops::Types::PTupleType.new(t.types[0..0].concat(types))) }\nend","tryCatchPattern":"begin\n  result = Init[Array[Integer], 3].new(*values)\nrescue ArgumentError => e\n  fail(\"Init args do not match any Array.new overload: #{e.message}\")\nend","preventionTips":["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."],"tags":["puppet","pcore","init-type","constructor-arguments","type-system"],"backgroundTag":"constructor-argument-mismatch","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}