puppetlabs/puppet · error · Puppet::ParseError

%{member} attempts to override %{label}

Error message

%{member} attempts to override %{label}

What it means

An overriding member must be the same kind of feature as the inherited member it replaces: an attribute overrides an attribute, a type parameter overrides a type parameter. assert_can_be_overridden checks instance_of?(member.class); a mismatch (attribute vs PTypeParameter) raises this Puppet::ParseError.

Source

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

        if @override
          raise Puppet::ParseError, _("expected %{label} to override an inherited %{feature_type}, but no such %{feature_type} was found") %
                                    { label: label, feature_type: feature_type }
        end
        self
      else
        parent_member.assert_can_be_overridden(self)
      end
    end

    # Checks if the given _member_ can override this member.
    #
    # @param member [PAnnotatedMember] the overriding member
    # @return [PAnnotatedMember] its argument
    # @raises [Puppet::ParseError] if the assertion fails
    # @api private
    def assert_can_be_overridden(member)
      unless instance_of?(member.class)
        raise Puppet::ParseError, _("%{member} attempts to override %{label}") % { member: member.label, label: label }
      end
      if @final && !(constant? && member.constant?)
        raise Puppet::ParseError, _("%{member} attempts to override final %{label}") % { member: member.label, label: label }
      end
      unless member.override?
        # TRANSLATOR 'override => true' is a puppet syntax and should not be translated
        raise Puppet::ParseError, _("%{member} attempts to override %{label} without having override => true") % { member: member.label, label: label }
      end
      unless @type.assignable?(member.type)
        raise Puppet::ParseError, _("%{member} attempts to override %{label} with a type that does not match") % { member: member.label, label: label }
      end

      member
    end

    def constant?
      false
    end

View on GitHub (pinned to e227c27540)

Solutions

  1. Keep the member in the same section as the parent: override the type parameter under 'type_parameters', or the attribute under 'attributes'.
  2. If the kind genuinely must change, use a new member name instead of overriding.
  3. Remove 'override' => true if you did not intend an override at all.

Example fix

# before — parent declares 'size' as a type_parameter, child re-declares it as an attribute
type Sub = Object[{'parent' => 'Base', 'attributes' => {'size' => {'type' => Integer, 'override' => true}}}]

# after — override it in the matching section
type Sub = Object[{'parent' => 'Base', 'type_parameters' => {'size' => {'type' => Integer, 'override' => true}}}]
Defensive patterns

Strategy: validation

Validate before calling

# Ruby — when building child types, keep members in the parent's section
(parent.type_parameters.key?(name) ? child_type_params : child_attributes)[name] = entry

Type guard

def same_member_kind?(parent_member, child_member)
  parent_member.instance_of?(child_member.class)
end

Try / catch

begin
  child_type = Puppet::Pops::Types::PObjectType.new(child_name, child_hash)
rescue Puppet::ParseError => e
  raise CompileError, "kind mismatch in override: #{e.message}"
end

Prevention

When it happens

Trigger: A child Object type defines an entry under 'attributes' with the same name as the parent's entry under 'type_parameters' (or vice versa), with override => true — the kinds differ, so the override is rejected.

Common situations: Promoting a parent's type parameter to a real attribute (or the reverse) in a subtype; hand-editing generated type hashes and moving entries between the two sections without renaming.

Related errors


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