Method: Puppet::Pops::Types::TypeMismatchDescriber#describe_PCallableType

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

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



945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 945

def describe_PCallableType(expected, original, actual, path)
  if actual.is_a?(PCallableType)
    # nil param_types means, any other Callable is assignable
    if expected.param_types.nil? && expected.return_type.nil?
      EMPTY_ARRAY
    else
      # NOTE: these tests are made in reverse as it is calling the callable that is constrained
      # (it's lower bound), not its upper bound
      param_errors = describe_argument_tuple(expected.param_types, actual.param_types, path)
      if param_errors.empty?
        this_return_t = expected.return_type || PAnyType::DEFAULT
        that_return_t = actual.return_type || PAnyType::DEFAULT
        if this_return_t.assignable?(that_return_t)
          # names are ignored, they are just information
          # Blocks must be compatible
          this_block_t = expected.block_type || PUndefType::DEFAULT
          that_block_t = actual.block_type || PUndefType::DEFAULT
          if that_block_t.assignable?(this_block_t)
            EMPTY_ARRAY
          else
            [TypeMismatch.new(path + [BlockPathElement.new], this_block_t, that_block_t)]
          end
        else
          [TypeMismatch.new(path + [ReturnTypeElement.new], this_return_t, that_return_t)]
        end
      else
        param_errors
      end
    end
  else
    [TypeMismatch.new(path, original, actual)]
  end
end