summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Parker <andy@puppetlabs.com>2014-10-06 14:56:25 -0700
committerAndrew Parker <andy@puppetlabs.com>2014-10-06 14:56:25 -0700
commit71add0db9fb0583589c52fdfc15f3937ebf493ff (patch)
treee1807dece093ccb3afb3c1770981f987e789dcd8
parentbcd40b357e4210692dd655835c6919821fd82e3f (diff)
parent13faa18fc5b774c540f5a368dc4ed165d061827d (diff)
downloadpuppet-71add0db9fb0583589c52fdfc15f3937ebf493ff.tar.gz
Merge branch 'pr/3136' into stable
* pr/3136: (PUP-3364) Improve the error message for numeric resource titles
-rw-r--r--lib/puppet/pops/evaluator/access_operator.rb14
-rw-r--r--lib/puppet/pops/evaluator/runtime3_support.rb1
-rw-r--r--spec/unit/pops/evaluator/evaluating_parser_spec.rb10
3 files changed, 9 insertions, 16 deletions
diff --git a/lib/puppet/pops/evaluator/access_operator.rb b/lib/puppet/pops/evaluator/access_operator.rb
index e849a2c4e..623fb1a60 100644
--- a/lib/puppet/pops/evaluator/access_operator.rb
+++ b/lib/puppet/pops/evaluator/access_operator.rb
@@ -232,7 +232,7 @@ class Puppet::Pops::Evaluator::AccessOperator
when :default
'Default'
else
- actual.class.name
+ Puppet::Pops::Types::TypeCalculator.generalize!(Puppet::Pops::Types::TypeCalculator.infer(actual)).to_s
end
end
@@ -462,7 +462,7 @@ class Puppet::Pops::Evaluator::AccessOperator
else
# blame given left expression if it defined the type, else the first given key expression
blame = o.type_name.nil? ? @semantic.keys[0] : @semantic.left_expr
- fail(Puppet::Pops::Issues::ILLEGAL_RESOURCE_SPECIALIZATION, blame, {:actual => type_name.class})
+ fail(Puppet::Pops::Issues::ILLEGAL_RESOURCE_SPECIALIZATION, blame, {:actual => bad_key_type_name(type_name)})
end
# type name must conform
@@ -508,18 +508,10 @@ class Puppet::Pops::Evaluator::AccessOperator
keys = [:no_title] if keys.size < 1 # if there was only a type_name and it was consumed
result = keys.each_with_index.map do |t, i|
unless t.is_a?(String) || t == :no_title
- type_to_report = case t
- when nil
- 'Undef'
- when :default
- 'Default'
- else
- t.class.name
- end
index = keys_orig_size != keys.size ? i+1 : i
fail(Puppet::Pops::Issues::BAD_TYPE_SPECIALIZATION, @semantic.keys[index], {
:type => o,
- :message => "Cannot use #{type_to_report} where String is expected"
+ :message => "Cannot use #{bad_key_type_name(t)} where a resource title String is expected"
})
end
diff --git a/lib/puppet/pops/evaluator/runtime3_support.rb b/lib/puppet/pops/evaluator/runtime3_support.rb
index 518b5216e..c1d8e42ff 100644
--- a/lib/puppet/pops/evaluator/runtime3_support.rb
+++ b/lib/puppet/pops/evaluator/runtime3_support.rb
@@ -394,6 +394,7 @@ module Puppet::Pops::Evaluator::Runtime3Support
# Returns true, if the given name is the name of a resource parameter.
#
def is_parameter_of_resource?(scope, resource, name)
+ return false unless name.is_a?(String)
resource.valid_parameter?(name)
end
diff --git a/spec/unit/pops/evaluator/evaluating_parser_spec.rb b/spec/unit/pops/evaluator/evaluating_parser_spec.rb
index bff009ddf..bc5b8bd66 100644
--- a/spec/unit/pops/evaluator/evaluating_parser_spec.rb
+++ b/spec/unit/pops/evaluator/evaluating_parser_spec.rb
@@ -680,12 +680,12 @@ describe 'Puppet::Pops::Evaluator::EvaluatorImpl' do
"'abc'[x]" => "The value 'x' cannot be converted to Numeric",
"'abc'[1.0]" => "A String[] cannot use Float where Integer is expected",
"'abc'[1,2,3]" => "String supports [] with one or two arguments. Got 3",
- "Resource[0]" => 'First argument to Resource[] must be a resource type or a String. Got Fixnum',
- "Resource[a, 0]" => 'Error creating type specialization of a Resource-Type, Cannot use Fixnum where String is expected',
- "File[0]" => 'Error creating type specialization of a File-Type, Cannot use Fixnum where String is expected',
+ "Resource[0]" => 'First argument to Resource[] must be a resource type or a String. Got Integer',
+ "Resource[a, 0]" => 'Error creating type specialization of a Resource-Type, Cannot use Integer where a resource title String is expected',
+ "File[0]" => 'Error creating type specialization of a File-Type, Cannot use Integer where a resource title String is expected',
"String[a]" => "A Type's size constraint arguments must be a single Integer type, or 1-2 integers (or default). Got a String",
- "Pattern[0]" => 'Error creating type specialization of a Pattern-Type, Cannot use Fixnum where String or Regexp or Pattern-Type or Regexp-Type is expected',
- "Regexp[0]" => 'Error creating type specialization of a Regexp-Type, Cannot use Fixnum where String or Regexp is expected',
+ "Pattern[0]" => 'Error creating type specialization of a Pattern-Type, Cannot use Integer where String or Regexp or Pattern-Type or Regexp-Type is expected',
+ "Regexp[0]" => 'Error creating type specialization of a Regexp-Type, Cannot use Integer where String or Regexp is expected',
"Regexp[a,b]" => 'A Regexp-Type[] accepts 1 argument. Got 2',
"true[0]" => "Operator '[]' is not applicable to a Boolean",
"1[0]" => "Operator '[]' is not applicable to an Integer",