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

Allow automatic conversion of string to numeric for certain comparisons

    Details

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

      Puppet 4.0.0

    • Template:

      Description

      The following code works with 3.7 and `--parser future` but not 4.0.0:

      if $::operatingsystemmajrelease >= 7 {

      The error is:

      Evaluation Error: Comparison of: String >= Integer, is not possible. Caused by 'A String is not comparable to a non String'.

      This appears to be a deliberate decision:
      https://github.com/puppetlabs/puppet-specifications/blob/master/language/types_values_variables.md#string-to-numeric-conversion
      "Automatic conversion between String and Numeric is performed for arithmetic operations, but not for comparisons."

      This means such code has to be written as:

      if scanf($::operatingsystemmajrelease, "%i")[0] >= 7 {

      Of course this specific example is fixed with cfactor, but I think there are plenty of other cases where similar behaviour is required. I'd like to request reconsideration of including automatic type casting for operators, at least in cases like >=. Explicit conversion is not pretty.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              alex.jurkiewicz Alex Jurkiewicz
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Zendesk Support