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

multiple literal default entries in case should raise warning or error under control by --strict

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: PUP 4.9.0
    • Component/s: Compiler
    • Labels:
      None
    • Template:
    • Acceptance Criteria:
      Hide

      That a duplicate literal default in a case or selector expression leads to no action, warning or error as controlled by the --strict option. The message should point to the first duplicated entry.

      Show
      That a duplicate literal default in a case or selector expression leads to no action, warning or error as controlled by the --strict option. The message should point to the first duplicated entry.
    • Epic Link:
    • Team:
      Puppet Developer Experience
    • Story Points:
      1
    • Sprint:
      PDE 2017-01-11
    • Release Notes:
      New Feature
    • Release Notes Summary:
      Duplicate literal default entries in case and selector expressions are now validated under the control of the --strict flag (defaults to warning).
    • QA Risk Assessment:
      No Action
    • QA Risk Assessment Reason:
      covered by unit tests; error message

      Description

      Multiple 'default' entries should result in a parse error. It creates an ambiguity. Consider the following examples:

      case 10 {
        default : { notice 'nbr1' }
        default : { notice 'nbr2' }
      }
      # => notices nbr 2
       
      case default {
        default : { notice 'nbr1 }
        default : { notice 'nbr2' }
      }
      # => notices nbr1
      

      The solution is to validate that only one option among all propositions is a literal default.

      UPDATE


      The check for this can only detect literal (i.e. static) duplication. This because it is possible to use any expression as a case option and we cannot evaluate all options as the language is specified to evaluate them sequentially until there is a match. Here is an illustration:

      $a = default
      case 10 {
        $a : { notice yay }
        default : { notice nay }
      }
      

      This will notice yay.

      It is not only duplication of literal default that can cause problems - a check could check for any static duplication since the option with a second identical value would never be reached. Such a check is however more expensive than only checking duplication of literal default since option values can be arbitrarily complex.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                henrik.lindberg Henrik Lindberg
                QA Contact:
                Eric Thompson
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Zendesk Support