Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-3978

Change how block is passed to avoid confusion with missing optional parameters


    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: PUP 3.7.5
    • Component/s: Language
    • Labels:
    • Template:
    • Story Points:
    • Sprint:
      Language 2015-02-18


      A puppet function created using optional parameters followed by a block, that then gets called without providing a value for those optional parameters, will cause the weaving logic to create an arguments array that is too short, leaving the block that is supposed to be last, at the wrong position (it's simply passed on at the position it's placed in by the caller).

      The fact that a block isn't really a block but a normal parameter in Ruby makes the optional parameter paradigm inconsistent in the dispatch declaration. It can only work without the block since in order to put the block last, a value must be present for each parameter in the invocation. This in turn means that using normal ruby syntax to set parameter default values will fail (passing nil overrides such a default setting).

      On solution would be to provide a parameter default value in the dispatch configuration as an optional third argument to param and require that the ruby method that the dispatch is targeting never has any optional parameters (the method arity must never be negative). The default value would be optional in itself and default to nil. When given, it must of course comply with the parameter type (which is another reason to put it there instead of in the ruby method declaration, defaults declare there doesn't have this requirement).


          Issue Links



              • Assignee:
                thomas.hallgren Thomas Hallgren
                QA Contact:
                Eric Thompson
              • Votes:
                0 Vote for this issue
                3 Start watching this issue


                • Created:

                  Zendesk Support