{"record":{"id":"b5aadcef54eccc86","repo":"puppetlabs/puppet","slug":"parameters-cannot-be-added-after-a-repeated-parame","errorCode":null,"errorMessage":"Parameters cannot be added after a repeated parameter","messagePattern":"Parameters cannot be added after a repeated parameter","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/functions.rb","lineNumber":536,"sourceCode":"\n    # Defines the return type. Defaults to 'Any'\n    # @param [String] type a reference to a Puppet Data Type\n    #\n    # @api public\n    def return_type(type)\n      unless type.is_a?(String) || type.is_a?(Puppet::Pops::Types::PAnyType)\n        raise ArgumentError, _(\"Argument to 'return_type' must be a String reference to a Puppet Data Type. Got %{type_class}\") % { type_class: type.class }\n      end\n\n      @return_type = type\n    end\n\n    private\n\n    # @api private\n    def internal_param(type, name, repeat = false)\n      raise ArgumentError, _('Parameters cannot be added after a block parameter') unless @block_type.nil?\n      raise ArgumentError, _('Parameters cannot be added after a repeated parameter') if @max == :default\n\n      if name.is_a?(String)\n        raise ArgumentError, _(\"Parameter name argument must be a Symbol. Got %{name_class}\") % { name_class: name.class }\n      end\n\n      if type.is_a?(String) || type.is_a?(Puppet::Pops::Types::PAnyType)\n        @types << type\n        @names << name\n        # mark what should be picked for this position when dispatching\n        if repeat\n          @weaving << -@names.size()\n        else\n          @weaving << @names.size() - 1\n        end\n      else\n        raise ArgumentError, _(\"Parameter 'type' must be a String reference to a Puppet Data Type. Got %{type_class}\") % { type_class: type.class }\n      end\n    end","sourceCodeStart":518,"sourceCodeEnd":554,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/functions.rb#L518-L554","documentation":"A repeated parameter sets @max to :default, marking the signature as variadic. internal_param rejects any later parameter declaration in that state, because nothing can bind after a 1..N capture. The repeated parameter must be last, or immediately before a block parameter.","triggerScenarios":"dispatch :m do required_repeated_param 'String', :rest; param 'String', :last end. The param line after the repeated line raises at definition time.","commonSituations":"Adding a trailing argument to a signature that already ends with a variadic capture; converting the last positional into a splat and forgetting to move earlier declarations.","solutions":["Move the fixed parameter above the repeated one.","If the trailing parameter is optional in practice, fold it into the repeated capture and default it inside the method body.","Remember the legal tail order: required params, optional params, repeated param, block param."],"exampleFix":"# before\n dispatch :m do\n   required_repeated_param 'String', :rest\n   param 'String', :last      # raises: parameter after repeated\n end\n\n# after: repeated parameter goes last (before any block)\n dispatch :m do\n   param 'String', :last\n   required_repeated_param 'String', :rest\n end","handlingStrategy":"validation","validationCode":"# CI grep: a param-style declaration after a repeated param in one dispatch block\n! grep -Pzo 'dispatch[^}]*(required_repeated_param|optional_repeated_param)[^}]*\\n[^}]*\\s(param|optional_param) ' lib/puppet/functions/**/*.rb","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat repeated params as terminal: nothing but a block param may follow.","Default trailing values inside the method body instead of adding params after a splat.","Re-read the whole dispatch block after any arity change."],"tags":["puppet","functions","dispatch","parameter-order","variadic"],"backgroundTag":"parameter-order-invalid","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}