summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast/astarray.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/parser/ast/astarray.rb')
-rw-r--r--lib/puppet/parser/ast/astarray.rb19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/puppet/parser/ast/astarray.rb b/lib/puppet/parser/ast/astarray.rb
index 529998e3c..432300c7a 100644
--- a/lib/puppet/parser/ast/astarray.rb
+++ b/lib/puppet/parser/ast/astarray.rb
@@ -9,6 +9,11 @@ class Puppet::Parser::AST
class ASTArray < Branch
include Enumerable
+ # True if this ASTArray represents a list of statements in a
+ # context that defines a namespace. Classes and definitions may
+ # only appear in such a context.
+ attr_accessor :is_a_namespace
+
# Return a child by index. Probably never used.
def [](index)
@children[index]
@@ -32,7 +37,19 @@ class Puppet::Parser::AST
}
rets = items.flatten.collect { |child|
- child.safeevaluate(scope)
+ if child.respond_to? :instantiate
+ if is_a_namespace
+ # no problem, just don't evaluate it.
+ else
+ msg = "Classes, definitions, and nodes may only appear at toplevel or inside other classes"
+ error = Puppet::Error.new(msg)
+ error.line = child.line
+ error.file = child.file
+ raise error
+ end
+ else
+ child.safeevaluate(scope)
+ end
}
rets.reject { |o| o.nil? }
end