{"record":{"id":"10d4a4ec53b615d2","repo":"puppetlabs/puppet","slug":"cannot-use-an-unspecific-class-type","errorCode":null,"errorMessage":"Cannot use an unspecific Class[] Type","messagePattern":"Cannot use an unspecific Class\\[\\] Type","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/parser/scope.rb","lineNumber":1096,"sourceCode":"  # @return [Array<String>] names after transformation\n  #\n  def transform_and_assert_classnames(names)\n    names.map do |name|\n      case name\n      when NilClass\n        raise ArgumentError, _(\"Cannot use undef as a class name\")\n      when String\n        raise ArgumentError, _(\"Cannot use empty string as a class name\") if name.empty?\n\n        name.sub(/^([^:]{1,2})/, '::\\1')\n\n      when Puppet::Resource\n        assert_class_and_title(name.type, name.title)\n        name.title.sub(/^([^:]{1,2})/, '::\\1')\n\n      when Puppet::Pops::Types::PClassType\n        # TRANSLATORS \"Class\" and \"Type\" are Puppet keywords and should not be translated\n        raise ArgumentError, _(\"Cannot use an unspecific Class[] Type\") unless name.class_name\n\n        name.class_name.sub(/^([^:]{1,2})/, '::\\1')\n\n      when Puppet::Pops::Types::PResourceType\n        assert_class_and_title(name.type_name, name.title)\n        name.title.sub(/^([^:]{1,2})/, '::\\1')\n      end.downcase\n    end\n  end\n\n  # Calls a 3.x or 4.x function by name with arguments given in an array using the 4.x calling convention\n  # and returns the result.\n  # Note that it is the caller's responsibility to rescue the given ArgumentError and provide location information\n  # to aid the user find the problem. The problem is otherwise reported against the source location that\n  # invoked the function that ultimately called this method.\n  #\n  # @return [Object] the result of the called function\n  # @raise ArgumentError if the function does not exist","sourceCodeStart":1078,"sourceCodeEnd":1114,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/parser/scope.rb#L1078-L1114","documentation":"Raised by Scope#transform_and_assert_classnames in the PClassType branch when a Class[] type reference carries no class_name. `Class` by itself (a PClassType with class_name == nil) matches any class as a type, but it is not a concrete class that can be included, contained, or realized, so normalization refuses it.","triggerScenarios":"`include Class` (bare, no title), `contain Class`, `Class <| tag == 'x' |>`-adjacent API misuse, or `include Class[$var]` where the interpolation degenerates to an unspecific Class type. Also direct calls like scope.transform_and_assert_classnames([Puppet::Pops::Types::TypeParser.parse('Class')]).","commonSituations":"Code intended to reference 'the Class metatype' in a type annotation accidentally passed to include; refactoring `Class['name']` references where the ['name'] part was dropped; generic code iterating over type objects and forwarding them to include.","solutions":["Name the class: `include Class['apache']` or simply `include apache`.","If the intent was a type check, keep Class on the right side of a match: `assert_type(Class, $ref)` — do not pass it to include.","In generic Ruby code, verify `klass.class_name` is non-nil before forwarding a PClassType to include/contain."],"exampleFix":"# before\ninclude Class          # Cannot use an unspecific Class[] Type\n\n# after\ninclude Class['apache'] # or: include apache","handlingStrategy":"validation","validationCode":"# DSL: always include a concrete name\ninclude Class['apache']\n# Ruby: check specificity before forwarding a type object\nraise ArgumentError, 'unspecific Class[]' unless pclass_type.class_name","typeGuard":"p.is_a?(Puppet::Pops::Types::PClassType) && !p.class_name.nil?","tryCatchPattern":null,"preventionTips":["Never pass bare Class/Resource metatypes to include/contain.","In generic code, verify .class_name / .type_name / .title are set before calling include-family APIs.","Keep Class[...] on the right side of =~ or assert_type for type checks."],"tags":["puppet","class-reference","type","include","metatype"],"backgroundTag":"invalid-class-reference","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}