{"record":{"id":"43d92ad65a014b75","repo":"puppetlabs/puppet","slug":"the-label-type-cannot-be-parameterized-using","errorCode":null,"errorMessage":"The %{label}-Type cannot be parameterized using []","messagePattern":"The %(.+?)-Type cannot be parameterized using \\[\\]","errorType":"exception","errorClass":"Puppet::ParseError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/types/p_object_type_extension.rb","lineNumber":55,"sourceCode":"  # @api private\n  def self.create_from_instance(base_type, instance)\n    type_parameters = base_type.type_parameters(true)\n    attrs = base_type.attributes(true)\n    params = type_parameters.keys.map do |pn|\n      attr = attrs[pn]\n      attr.nil? ? nil : instance.send(pn)\n    end\n    create(base_type, params)\n  end\n\n  def [](name)\n    @base_type[name]\n  end\n\n  # @api private\n  def initialize(base_type, init_parameters)\n    pts = base_type.type_parameters(true)\n    raise Puppet::ParseError, _('The %{label}-Type cannot be parameterized using []') % { label: base_type.label } if pts.empty?\n\n    @base_type = base_type\n\n    named_args = init_parameters.size == 1 && init_parameters[0].is_a?(Hash)\n    if named_args\n      # Catch case when first parameter is an assignable Hash\n      named_args = pts.size >= 1 && !pts.values[0].type.instance?(init_parameters[0])\n    end\n\n    by_name = {}\n    if named_args\n      hash = init_parameters[0]\n      hash.each_pair do |pn, pv|\n        tp = pts[pn]\n        if tp.nil?\n          raise Puppet::ParseError, _(\"'%{pn}' is not a known type parameter for %{label}-Type\") % { pn: pn, label: base_type.label }\n        end\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/types/p_object_type_extension.rb#L37-L73","documentation":"PObjectTypeExtension wraps an Object type parameterized with [], e.g. MyApp::Color[3]. Parameterization only works when the type declares type_parameters (own or inherited); the constructor raises Puppet::ParseError when the base type's type_parameters map is empty, because there is nothing for the bracket arguments to bind to.","triggerScenarios":"Writing MyApp::Color[3] or MyApp::Color[{channel => 3}] in Puppet code when the MyApp::Color Object type declares only attributes (or nothing) under type_parameters. Attributes do not make a type parameterizable - only type_parameters do.","commonSituations":"Confusing attributes with type_parameters: expecting MyType[{attr => val}] to act as a struct-style instance check; using a type alias parameterization style on a plain Object type; migrating from Variant/Struct patterns.","solutions":["If you want a parameterizable type, declare type_parameters => { channel => Type[Integer] } (each with a type) in the Object definition, then use MyApp::Color[3]","If you meant to match instances by attribute values, do not parameterize: rely on type inference or write a function that checks the attribute values"],"exampleFix":"# before\ntype MyApp::Color = Object[{ attributes => { value => Integer } }]\n$three = MyApp::Color[3]        # ParseError: no type_parameters\n\n# after\ntype MyApp::Color = Object[{\n  type_parameters => { channel => Integer },\n  attributes => { value => Integer }\n}]\n$three = MyApp::Color[3]","handlingStrategy":"type-guard","validationCode":"# Ruby: only parameterize types that declare type parameters\npts = base_type.type_parameters(true)\nraise \"#{base_type.label} declares no type_parameters; cannot use []\" if pts.empty?","typeGuard":"def parameterizable?(type)\n  type.respond_to?(:type_parameters) && !type.type_parameters(true).empty?\nend","tryCatchPattern":"begin\n  Puppet::Pops::Types::PObjectTypeExtension.create(base_type, args)\nrescue Puppet::ParseError => e\n  raise unless e.message =~ /cannot be parameterized using \\[\\]/\n  base_type  # fall back semantics live with the caller: use the unparameterized type deliberately\nend","preventionTips":["Distinguish type_parameters (compile-time, used with []) from attributes (per-instance)","Declare type_parameters with an explicit type for each before using bracket syntax"],"tags":["puppet","pcore","object-type","type-parameters","dsl"],"backgroundTag":"invalid-type-parameterization","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}