{"record":{"id":"c0c0325d2f4a5ec5","repo":"puppetlabs/puppet","slug":"member-attempts-to-override-label-with-a-typ","errorCode":null,"errorMessage":"%{member} attempts to override %{label} with a type that does not match","messagePattern":"%(.+?) attempts to override %(.+?) with a type that does not match","errorType":"exception","errorClass":"Puppet::ParseError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/types/p_object_type.rb","lineNumber":184,"sourceCode":"    # Checks if the given _member_ can override this member.\n    #\n    # @param member [PAnnotatedMember] the overriding member\n    # @return [PAnnotatedMember] its argument\n    # @raises [Puppet::ParseError] if the assertion fails\n    # @api private\n    def assert_can_be_overridden(member)\n      unless instance_of?(member.class)\n        raise Puppet::ParseError, _(\"%{member} attempts to override %{label}\") % { member: member.label, label: label }\n      end\n      if @final && !(constant? && member.constant?)\n        raise Puppet::ParseError, _(\"%{member} attempts to override final %{label}\") % { member: member.label, label: label }\n      end\n      unless member.override?\n        # TRANSLATOR 'override => true' is a puppet syntax and should not be translated\n        raise Puppet::ParseError, _(\"%{member} attempts to override %{label} without having override => true\") % { member: member.label, label: label }\n      end\n      unless @type.assignable?(member.type)\n        raise Puppet::ParseError, _(\"%{member} attempts to override %{label} with a type that does not match\") % { member: member.label, label: label }\n      end\n\n      member\n    end\n\n    def constant?\n      false\n    end\n\n    # @return [Boolean] `true` if this feature cannot be overridden\n    # @api public\n    def final?\n      @final\n    end\n\n    # @return [Boolean] `true` if this feature must override an inherited feature\n    # @api public\n    def override?","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/types/p_object_type.rb#L166-L202","documentation":"An overriding member's type must be assignable from the perspective of the inherited member: the parent's @type.assignable?(member.type) must hold, i.e. the child type must be a subtype (narrower or equal). Redeclaring with an unrelated or wider type raises this Puppet::ParseError.","triggerScenarios":"Parent declares 'size' => Integer (or Numeric); child declares 'size' => {'type' => String, 'override' => true}; String is not assignable to Integer so the check fails. Widening (parent Integer, child Numeric) also fails.","commonSituations":"Assuming override => true permits any type change; attempting to widen a parent contract for 'flexibility'; narrowing in the wrong direction (parent String, child Enum when the enum values do not fit).","solutions":["Make the child's type a subtype of the parent's: parent 'Any' -> child 'String' is fine; parent 'Integer' -> child 'Integer[1,10]' is fine.","If you need a different contract, use a new member name instead of overriding.","If you own the parent, widen the parent type deliberately (accepting the contract change for all subclasses)."],"exampleFix":"# before — Base: 'size' => Integer\ntype Sub = Object[{'parent' => 'Base', 'attributes' => {'size' => {'type' => String, 'override' => true}}}]\n\n# after — narrow, don't change kind\ntype Sub = Object[{'parent' => 'Base', 'attributes' => {'size' => {'type' => Integer[1, 100], 'override' => true}}}]","handlingStrategy":"validation","validationCode":"# Ruby — verify subtype relation before declaring an override\ntc = Puppet::Pops::Types::TypeCalculator.singleton\nfail(\"#{name}: #{child_type} is not assignable to inherited #{parent_type}\") unless tc.assignable?(parent_type, child_type)","typeGuard":"def narrower_type?(parent_type, child_type)\n  Puppet::Pops::Types::TypeCalculator.singleton.assignable?(parent_type, child_type)\nend","tryCatchPattern":"begin\n  Puppet::Pops::Types::PObjectType.new(name, hash)\nrescue Puppet::ParseError => e\n  raise CompileError, \"override type mismatch: #{e.message} (child type must be a subtype)\"\nend","preventionTips":["Remember assignability direction: parent.assignable?(child) must be true — child narrows parent.","Prefer Integer[1,10] under Integer or Enum under String; never change the data kind."],"tags":["puppet","object-type","inheritance","override","type-mismatch"],"backgroundTag":"override-type-mismatch","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}