puppetlabs/puppet · error · Puppet::ParseError

%{label} conflicts with attribute with the same name

Error message

%{label} conflicts with attribute with the same name

What it means

An Object type may declare both attributes and functions, but they share one member namespace on the generated class. When a function is created whose name equals an already-declared attribute name, Puppet::ParseError is raised stating that the function label conflicts with an attribute of the same name.

Source

Thrown at lib/puppet/pops/types/p_object_type.rb:775

    unless attr_specs.empty?
      @attributes = attr_specs.to_h do |key, attr_spec|
        unless attr_spec.is_a?(Hash)
          attr_type = TypeAsserter.assert_instance_of(nil, PTypeType::DEFAULT, attr_spec) { "attribute #{label}[#{key}]" }
          attr_spec = { KEY_TYPE => attr_type }
          attr_spec[KEY_VALUE] = nil if attr_type.is_a?(POptionalType)
        end
        attr = PAttribute.new(key, self, attr_spec)
        [attr.name, attr.assert_override(parent_members)]
      end.freeze
    end

    func_specs = init_hash[KEY_FUNCTIONS]
    unless func_specs.nil? || func_specs.empty?
      @functions = func_specs.to_h do |key, func_spec|
        func_spec = { KEY_TYPE => TypeAsserter.assert_instance_of(nil, TYPE_FUNCTION_TYPE, func_spec) { "function #{label}[#{key}]" } } unless func_spec.is_a?(Hash)
        func = PFunction.new(key, self, func_spec)
        name = func.name
        raise Puppet::ParseError, _("%{label} conflicts with attribute with the same name") % { label: func.label } if @attributes.include?(name)

        [name, func.assert_override(parent_members)]
      end.freeze
    end

    @equality_include_type = init_hash[KEY_EQUALITY_INCLUDE_TYPE]
    @equality_include_type = true if @equality_include_type.nil?

    equality = init_hash[KEY_EQUALITY]
    equality = [equality] if equality.is_a?(String)
    if equality.is_a?(Array)
      unless equality.empty?
        # TRANSLATORS equality_include_type = false should not be translated
        raise Puppet::ParseError, _('equality_include_type = false cannot be combined with non empty equality specification') unless @equality_include_type

        parent_eq_attrs = nil
        equality.each do |attr_name|
          attr = parent_members[attr_name]

View on GitHub (pinned to e227c27540)

Solutions

  1. Rename either the function or the attribute so both names are unique within the type (e.g. size vs size_label)
  2. If the function was meant to replace an inherited attribute's behavior, override the attribute instead of declaring a same-named function

Example fix

# before
type MyApp::T = Object[{
  attributes => { size => Integer },
  functions => { size => Callable[[], String] }
}]

# after
type MyApp::T = Object[{
  attributes => { size => Integer },
  functions => { size_label => Callable[[], String] }
}]
Defensive patterns

Strategy: validation

Validate before calling

# assert function names and attribute names are disjoint
overlap = (func_specs.keys & attr_specs.keys)
raise "function/attribute name conflict: #{overlap.inspect}" unless overlap.empty?

Try / catch

begin
  Puppet::Pops::Types::PObjectType.new(name, init_hash)
rescue Puppet::ParseError => e
  raise unless e.message =~ /conflicts with attribute with the same name/
  raise  # e.message names the function; rename it or the attribute
end

Prevention

When it happens

Trigger: A type definition with functions => { size => Callable[[], String] } while size is also declared (or inherited onto this type's own attribute map) under attributes => { size => Integer }. The check runs during type resolution, before any instance exists.

Common situations: Adding a derived-value function whose name naturally collides with an attribute (size, name, version); renaming members on one side only; inheriting members from a parent and redefining the name as a function in the child.

Related errors


AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21). Data as JSON: /api/errors/7249217681e6daf1. Report an issue: GitHub.