The following manifest:
case $var {
  /match/: {
     if $var =~ /matchagain/ {
     }
  }
}

is failing because the "=~" operators when matching sets an ephemeral
variable in the scope. But the case regex also did it, and since they
both belong to the same scope, and Puppet variables are immutables, the
scope raises an error.

The current patch is not the correct fix (which would be to create
a subscope each time we cross an '{', but would be much harder to
produce). Instead it makes the ephemeral variable not immutables
anymore, preventing raising an error. Since ephemeral variables
are very local, I don't think this would cause any harm.

Signed-off-by: Brice Figureau <[email protected]>
---
 lib/puppet/parser/scope.rb |    2 +-
 spec/unit/parser/scope.rb  |   12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index d6d6630..f03dc08 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -296,7 +296,7 @@ class Puppet::Parser::Scope
         table = options[:ephemeral] ? @ephemeral : @symtable
         #Puppet.debug "Setting %s to '%s' at level %s mode append %s" %
         #    [name.inspect,value,self.level, append]
-        if table.include?(name)
+        if table.include?(name) and !options[:ephemeral]
             unless options[:append]
                 error = Puppet::ParseError.new("Cannot reassign variable %s" % 
name)
             else
diff --git a/spec/unit/parser/scope.rb b/spec/unit/parser/scope.rb
index d7800e4..cd4484d 100755
--- a/spec/unit/parser/scope.rb
+++ b/spec/unit/parser/scope.rb
@@ -221,6 +221,18 @@ describe Puppet::Parser::Scope do
 
             @scope.lookupvar("myvar", false).should == :value1
         end
+
+        it "should not raise an error when setting it again" do
+            @scope.setvar("1", :value2, :ephemeral => true)
+            lambda { @scope.setvar("1", :value3, :ephemeral => true) 
}.should_not raise_error
+        end
+
+        it "should overwrite ephemeral values" do
+            @scope.setvar("1", :value1, :ephemeral => true)
+            @scope.setvar("1", :value2, :ephemeral => true)
+
+            @scope.lookupvar("1").should == :value2
+        end
     end
 
     describe "when interpolating string" do
-- 
1.6.6.1

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to