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

Selector expression ignored in some scenarios

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: PUP 5.3.2
    • Fix Version/s: PUP 5.4.0
    • Component/s: Language
    • Labels:
    • Environment:

      Ubuntu 16.04, CentOS 7
      Installed via puppet5-release repositories

    • Template:
    • Acceptance Criteria:
      Hide

      This manifest:

      $value = 3
       
      $test = [
        'I am',
        $value > 3 ? {
          default => 'less than or equal to three',
          true    => 'larger than three',
        },
      ].join(' ')
      

      will not produce an error, and:

      function test_broken ($item) {
        $value =~ /\d/ ? {
          default => 'non-numeric',
          true    => 'numeric',
        }
      }
      

      will return either 'numeric' or 'non-numeric'.

      Show
      This manifest: $value = 3   $test = [ 'I am' , $value > 3 ? { default => 'less than or equal to three' , true => 'larger than three' , }, ].join( ' ' ) will not produce an error, and: function test_broken ( $item ) { $value =~ /\d/ ? { default => 'non-numeric' , true => 'numeric' , } } will return either 'numeric' or 'non-numeric'.
    • Epic Link:
    • Team:
      Platform Core
    • Sprint:
      Platform Core KANBAN
    • Method Found:
      Needs Assessment
    • Release Notes:
      Bug Fix
    • Release Notes Summary:
      Hide
      The precedence of the '?' selector-operator was too high
      and this made it difficult to use an expression on the left hand side. As an example:
      {code:puppet}
      1 + 2 ? { 3 => expected, default => bad }
      {code}
      resulted in 'bad'.

      The precedence has now been changed to be just above {{and / or}}.
      Show
      The precedence of the '?' selector-operator was too high and this made it difficult to use an expression on the left hand side. As an example: {code:puppet} 1 + 2 ? { 3 => expected, default => bad } {code} resulted in 'bad'. The precedence has now been changed to be just above {{and / or}}.
    • QA Risk Assessment:
      No Action

      Description

      Hello,

      In some situations, a selector expression will be ignored in favor of the statement that it's testing. This seems like an operator precedence problem.

      The following manifest should notify two lines, "I am an array", and "I am still an array":

      $value = 'nonsense'
       
      $test = [
        'I am',
        $value =~ Array ? {
          default => 'not an array',
          true    => 'an array',
        },
      ].join(' ')
       
      $test2 = [
        'I am still',
        ($value =~ Array) ? {
          default => 'not an array',
          true    => 'an array',
        },
      ].join(' ')
       
      notify{ $test: }
      notify{ $test2: }
      

      Instead, the first notify becomes "I am false", because "$value =~ Array" resolves without consulting the selector.
      The parentheses in $test2's assignment seem to workaround this behavior.

      And similarly in a function, the same occurs due to implicit returning:

      $value = 'asdasd'
       
      function test_broken ($item) {
        $value =~ /\d/ ? {
          default => 'non-numeric',
          true    => 'numeric',
        }
      }
       
      function test_works ($item) {
        ($value =~ /\d/) ? {
          default => 'non-numeric',
          true    => 'numeric',
        }
      }
      $x = test_broken($value)
      $y = test_works($value)
      notify{ "$x": }
      notify{ "$y": }
      

      The following manifest should notify 'I am less than or equal to three'::

      $value = 3
       
      $test = [
        'I am',
        $value > 3 ? {
          default => 'less than or equal to three',
          true    => 'larger than three',
        },
      ].join(' ')
      

      The parser instead errors with:

      Evaluation Error: Comparison of: Integer > String, is not possible. Caused by 'A Numeric is not comparable to non Numeric'. at /test.pp:5:10
      

      If I can provide further information or help in any way with this issue, please let me know.

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            tprobinson Trevor Robinson
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Zendesk Support