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

deprecate that defining a class twice "merges" their behaviors

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: PUP 3.4.3, PUP 4.2.1
    • Fix Version/s: PUP 4.5.0
    • Component/s: Compiler
    • Labels:
      None
    • Environment:

      PE 3.2.1

    • Template:
    • Story Points:
      2
    • Sprint:
      Language 2016-03-09
    • CS Priority:
      Reviewed
    • Release Notes:
      New Feature
    • Release Notes Summary:
      Hide
      The option --strict=warning/error will now raise an error if a class is redefined.
      The current behavior that two classes with the same name are silently merged is now deprecated and will be removed in the next major release. The result of the current (now deprecated) behavior depends on the order the definitions are loaded and if the class was included before or after the merge.
      Show
      The option --strict=warning/error will now raise an error if a class is redefined. The current behavior that two classes with the same name are silently merged is now deprecated and will be removed in the next major release. The result of the current (now deprecated) behavior depends on the order the definitions are loaded and if the class was included before or after the merge.

      Description

      A new hire (Erin Buckley) is working through exercises and inadvertently defined a class twice in a file with surprising results.

      class test {
        notice('testing')
        notify { 'first': }
      }
       
      class test {
        notice('again')
        notify { 'surprise!': }
      }
       
      include test
      

      [root@student ~]# puppet apply test.pp
      Notice: Scope(Class[Test]): testing
      Notice: Scope(Class[Test]): again
      Notice: Compiled catalog for student.puppetlabs.vm in environment production in 0.04 seconds
      Notice: surprise!
      Notice: /Stage[main]/Test/Notify[surprise!]/message: defined 'message' as 'surprise!'
      Notice: first
      Notice: /Stage[main]/Test/Notify[first]/message: defined 'message' as 'first'
      Notice: Finished catalog run in 0.18 seconds
      

      Shouldn't the parser error out on this? If not that, shouldn't the second definition replace the first? I would never expect this combining effect.

      This should be controlled by the new --strict flag (PUP-5889). When it is set to warning or error output should be produced to indicate the problem.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                ben.ford Ben Ford
                QA Contact:
                Kurt Wall
              • Votes:
                2 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Zendesk Support