Method: Puppet::Pops::Types::TypeMismatchDescriber#describe_PVariantType

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

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



737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 737

def describe_PVariantType(expected, original, actual, path)
  variant_descriptions = []
  types = expected.types
  types = [PUndefType::DEFAULT] + types if original.is_a?(POptionalType)
  types.each_with_index do |vt, index|
    d = describe(vt, actual, path + [VariantPathElement.new(index)])
    return EMPTY_ARRAY if d.empty?

    variant_descriptions << d
  end
  descriptions = merge_descriptions(path.length, SizeMismatch, variant_descriptions)
  if original.is_a?(PTypeAliasType) && descriptions.size == 1
    # All variants failed in this alias so we report it as a mismatch on the alias
    # rather than reporting individual failures of the variants
    [TypeMismatch.new(path, original, actual)]
  else
    descriptions
  end
end