Method: Puppet::Pops::Types::TypeMismatchDescriber#describe_PArrayType

Defined in:
lib/puppet/pops/types/type_mismatch_describer.rb

#describe_PArrayType(expected, original, actual, path) ⇒ 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.



797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 797

def describe_PArrayType(expected, original, actual, path)
  descriptions = []
  element_type = expected.element_type || PAnyType::DEFAULT
  case actual
  when PTupleType
    types = actual.types
    expected_size = expected.size_type || PCollectionType::DEFAULT_SIZE
    actual_size = actual.size_type || PIntegerType.new(types.size, types.size)
    if expected_size.assignable?(actual_size)
      types.each_with_index do |type, idx|
        descriptions.concat(describe(element_type, type, path + [ArrayPathElement.new(idx)])) unless element_type.assignable?(type)
      end
    else
      descriptions << SizeMismatch.new(path, expected_size, actual_size)
    end
  when PArrayType
    expected_size = expected.size_type
    actual_size = actual.size_type || PCollectionType::DEFAULT_SIZE
    if expected_size.nil? || expected_size.assignable?(actual_size)
      descriptions << TypeMismatch.new(path, original, PArrayType.new(actual.element_type))
    else
      descriptions << SizeMismatch.new(path, expected_size, actual_size)
    end
  else
    descriptions << TypeMismatch.new(path, original, actual)
  end
  descriptions
end