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

Parser functions have arguments passed by reference rather than value

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Normal
    • Resolution: Won't Fix
    • Affects Version/s: PUP 3.4.3
    • Fix Version/s: None
    • Component/s: Compiler
    • Labels:
      None

      Description

      Variables in puppet manifests are immutable, for the most part, and parser functions are functions: they shouldn't have side effects on their inputs.

      However, as the programing interface for functions passes by reference, all sorts of side effect shenanigans are possible. For example, this is the main guts of the 4.1.0 stdlib concat function:

        a = arguments[0]
        b = arguments[1]
        
        result = a.concat(b)
       
        return result
      

      This will result in the first array argument having the second concatenated to it, and a reference to that array being returned, such that this manifest:

      $array1 = ['a', b', 'c']
      $array2 = ['d', 'e', 'f']
      $result = concat($array1, $array2)
      

      ...will result in $array1 having the same value as $result. Undesirable.

      To avoid this nonsense I have to indirectly duplicate my first array via another function before feeding it to concat:

      $array1 = ['a', b', 'c']
      $array1_dup = suffix($array1, '')
      $array2 = ['d', 'e', 'f']
      $result = concat($array1_dup, $array2)
      

      Not ideal.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                jwm John Morton
                QA Contact:
                Kurt Wall
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Zendesk Support