{"record":{"id":"bfd98f63e4d44964","repo":"puppetlabs/puppet","slug":"label-equality-is-referencing-constant-attrib","errorCode":null,"errorMessage":"%{label} equality is referencing constant %{attribute}. Reference to constant is not allowed in equality","messagePattern":"%(.+?) equality is referencing constant %(.+?)\\. Reference to constant is not allowed in equality","errorType":"exception","errorClass":"Puppet::ParseError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/types/p_object_type.rb","lineNumber":815,"sourceCode":"            # Assert that attribute is not already include by parent equality\n            parent_eq_attrs ||= parent_object_type.equality_attributes\n            if parent_eq_attrs.include?(attr_name)\n              including_parent = find_equality_definer_of(attr)\n              raise Puppet::ParseError, _(\"%{label} equality is referencing %{attribute} which is included in equality of %{including_parent}\") %\n                                        { label: label, attribute: attr.label, including_parent: including_parent.label }\n            end\n          end\n\n          unless attr.is_a?(PAttribute)\n            if attr.nil?\n              raise Puppet::ParseError, _(\"%{label} equality is referencing non existent attribute '%{attribute}'\") % { label: label, attribute: attr_name }\n            end\n\n            raise Puppet::ParseError, _(\"%{label} equality is referencing %{attribute}. Only attribute references are allowed\") %\n                                      { label: label, attribute: attr.label }\n          end\n          if attr.kind == ATTRIBUTE_KIND_CONSTANT\n            raise Puppet::ParseError, _(\"%{label} equality is referencing constant %{attribute}.\") % { label: label, attribute: attr.label } + ' ' +\n                                      _(\"Reference to constant is not allowed in equality\")\n          end\n        end\n      end\n      equality.freeze\n    end\n    @equality = equality\n\n    @checks = init_hash[KEY_CHECKS]\n    init_annotatable(init_hash)\n  end\n\n  def [](name)\n    member = @attributes[name] || @functions[name]\n    if member.nil?\n      rp = resolved_parent\n      member = rp[name] if rp.is_a?(PObjectType)\n    end","sourceCodeStart":797,"sourceCodeEnd":833,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/types/p_object_type.rb#L797-L833","documentation":"Constants declared in an Object type are folded into the attribute map with kind ATTRIBUTE_KIND_CONSTANT, and by design they are excluded from equality - every instance of the type carries the same constant value, so comparing it is meaningless and it cannot be overridden. Referencing a constant-kind attribute in an explicit equality list therefore raises Puppet::ParseError.","triggerScenarios":"A type with constants => { version => '1.0' } that also lists equality => ['version']. The entry resolves to a PAttribute, passes the existence and type checks, but its kind is constant, triggering the final check in the equality loop.","commonSituations":"Adding a constant to a type whose equality list previously referenced a regular attribute of the same name; attempting to make version/build metadata part of instance identity.","solutions":["Remove the constant from the equality list - constants never distinguish instances","If the value truly varies per instance and must affect equality, declare it as a regular attribute instead of a constant"],"exampleFix":"# before\ntype MyApp::T = Object[{\n  constants => { version => '1.0' },\n  equality => ['version']\n}]\n\n# after\ntype MyApp::T = Object[{\n  constants => { version => '1.0' }\n  # default equality covers all non-constant attributes\n}]","handlingStrategy":"validation","validationCode":"# constants must not appear in the equality list\nconst_names = type.attributes(true).select { |_, a| a.kind == Puppet::Pops::Types::PAttribute::ATTRIBUTE_KIND_CONSTANT }.keys\nbad = equality_list & const_names\nraise \"equality references constants: #{bad.inspect}\" unless bad.empty?","typeGuard":null,"tryCatchPattern":"begin\n  Puppet::Pops::Types::PObjectType.new(name, init_hash)\nrescue Puppet::ParseError => e\n  raise unless e.message =~ /Reference to constant is not allowed in equality/\n  raise  # drop the constant from the equality list\nend","preventionTips":["Keep constants out of equality lists - they are identical across all instances by definition","If a value must vary per instance and affect equality, make it an attribute, not a constant"],"tags":["puppet","pcore","object-type","equality","constants"],"backgroundTag":"invalid-equality-definition","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}