Method: Puppet::Pops::Types::TypeMismatchDescriber#describe_tuple
- Defined in:
- lib/puppet/pops/types/type_mismatch_describer.rb
#describe_tuple(expected, original, actual, path, size_mismatch_class) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 |
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 896 def describe_tuple(expected, original, actual, path, size_mismatch_class) return EMPTY_ARRAY if expected == actual || expected.types.empty? && actual.is_a?(PArrayType) expected_size = expected.size_type || TypeFactory.range(*expected.size_range) case actual when PTupleType actual_size = actual.size_type || TypeFactory.range(*actual.size_range) # not assignable if the number of types in actual is outside number of types in expected if expected_size.assignable?(actual_size) etypes = expected.types descriptions = [] unless etypes.empty? actual.types.each_with_index do |atype, index| adx = index >= etypes.size ? etypes.size - 1 : index descriptions.concat(describe(etypes[adx], atype, path + [ArrayPathElement.new(adx)])) end end descriptions else [size_mismatch_class.new(path, expected_size, actual_size)] end when PArrayType t2_entry = actual.element_type if t2_entry.nil? # Array of anything can not be assigned (unless tuple is tuple of anything) - this case # was handled at the top of this method. # [TypeMismatch.new(path, original, actual)] else expected_size = expected.size_type || TypeFactory.range(*expected.size_range) actual_size = actual.size_type || PCollectionType::DEFAULT_SIZE if expected_size.assignable?(actual_size) descriptions = [] expected.types.each_with_index do |etype, index| descriptions.concat(describe(etype, actual.element_type, path + [ArrayPathElement.new(index)])) end descriptions else [size_mismatch_class.new(path, expected_size, actual_size)] end end else [TypeMismatch.new(path, original, actual)] end end |