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

Add migration check for type mismatch in case/selector options

    XMLWordPrintable

Details

    • New Feature
    • Status: Closed
    • Normal
    • Resolution: Done
    • None
    • PUP 3.8.0, PUP 4.1.0
    • None
    • None

    Description

      In 4.0, comparison of String and Number is different (see PUP-4126). When there is a mismatch in case and selector options however, this leads to the option being skipped (there is never an error).

      The case and selector uses the evaluator_impl#is_match?, and it must check if the match is between Number and String.

      We also need to report the corner case of matching with regular expressions against something that is not a String. As illustrated here:

      $a = [1,2,3]
       
      case $a {
        /2/     : { notice '3x herp derp' }
        default : { notice 'sane 4x' }
      }
      

      Add the issue MIGRATE4_OPTION_TYPE_MISMATCH to MigrationIssues with the text "#{the_uc(semantic) will never be selected since a value of type '#{left.class}}' cannot match a value of type '#{right.class}}' (3.x. may match if values in string form match)".

      Add a report_option_type_mismatch(test_value, option_value, option_expr, matching_expr) where the option_expr is the case or selector option/entry, and the matching_expr is the case option value expression or the selector entry matching_expr (the selector entry only has one, the case option has multiple values that needs to be reported).

      Modify the is_match? method so it can pass the semantic objects on to the report method.

      (Add method stubs to the MigrationChecker in the puppet repository and the concrete methods to the implementation in the module created in PUP-4149).

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              henrik.lindberg Henrik Lindberg
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support