Method: Puppet::Pops::Types::TypeMismatchDescriber#describe_PHashType

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

#describe_PHashType(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.



826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 826

def describe_PHashType(expected, original, actual, path)
  descriptions = []
  key_type = expected.key_type || PAnyType::DEFAULT
  value_type = expected.value_type || PAnyType::DEFAULT
  case actual
  when PStructType
    elements = actual.elements
    expected_size = expected.size_type || PCollectionType::DEFAULT_SIZE
    actual_size = PIntegerType.new(elements.count { |a| !a.key_type.assignable?(PUndefType::DEFAULT) }, elements.size)
    if expected_size.assignable?(actual_size)
      elements.each do |a|
        descriptions.concat(describe(key_type, a.key_type, path + [EntryKeyPathElement.new(a.name)])) unless key_type.assignable?(a.key_type)
        descriptions.concat(describe(value_type, a.value_type, path + [EntryValuePathElement.new(a.name)])) unless value_type.assignable?(a.value_type)
      end
    else
      descriptions << SizeMismatch.new(path, expected_size, actual_size)
    end
  when PHashType
    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, PHashType.new(actual.key_type, actual.value_type))
    else
      descriptions << SizeMismatch.new(path, expected_size, actual_size)
    end
  else
    descriptions << TypeMismatch.new(path, original, actual)
  end
  descriptions
end