128 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc12module m3 type :: pdt(len)4 integer, len :: len5 character(len=len) :: ch6 end type7 contains8 pure real function f(x,y)9 real, intent(in) :: x, y10 f = x + y11 end function12 impure real function f1(x,y)13 f1 = x + y14 end function15 pure function f2(x,y)16 real :: f2(1)17 real, intent(in) :: x, y18 f2(1) = x + y19 end function20 pure real function f3(x,y,z)21 real, intent(in) :: x, y, z22 f3 = x + y + z23 end function24 pure real function f4(x,y)25 interface26 pure real function x(); end function27 pure real function y(); end function28 end interface29 f4 = x() + y()30 end function31 pure integer function f5(x,y)32 real, intent(in) :: x, y33 f5 = x + y34 end function35 pure real function f6(x,y)36 real, intent(in) :: x(*), y(*)37 f6 = x(1) + y(1)38 end function39 pure real function f7(x,y)40 real, intent(in), allocatable :: x41 real, intent(in) :: y42 f7 = x + y43 end function44 pure real function f8(x,y)45 real, intent(in), pointer :: x46 real, intent(in) :: y47 f8 = x + y48 end function49 pure real function f9(x,y)50 real, intent(in), optional :: x51 real, intent(in) :: y52 f9 = x + y53 end function54 pure real function f10a(x,y)55 real, intent(in), asynchronous :: x56 real, intent(in) :: y57 f10a = x + y58 end function59 pure real function f10b(x,y)60 real, intent(in), target :: x61 real, intent(in) :: y62 f10b = x + y63 end function64 pure real function f10c(x,y)65 real, intent(in), value :: x66 real, intent(in) :: y67 f10c = x + y68 end function69 pure function f11(x,y) result(res)70 type(pdt(*)), intent(in) :: x, y71 type(pdt(max(x%len, y%len))) :: res72 res%ch = x%ch // y%ch73 end function74 subroutine bad_reduce75 end subroutine76 77 subroutine errors78 real :: a(10,10), b, c(10)79 !ERROR: OPERATION= argument of REDUCE() must be a pure function of two data arguments80 b = reduce(a, f1)81 !ERROR: OPERATION= argument of REDUCE() must be a scalar function82 b = reduce(a, f2)83 !ERROR: OPERATION= argument of REDUCE() must be a pure function of two data arguments84 b = reduce(a, f3)85 !ERROR: OPERATION= argument of REDUCE() may not have dummy procedure arguments86 b = reduce(a, f4)87 !ERROR: OPERATION= argument of REDUCE() must have the same type as ARRAY=88 b = reduce(a, f5)89 !ERROR: Arguments of OPERATION= procedure of REDUCE() must be both scalar of the same type as ARRAY=, and neither allocatable, pointer, polymorphic, nor optional90 b = reduce(a, f6)91 !ERROR: Arguments of OPERATION= procedure of REDUCE() must be both scalar of the same type as ARRAY=, and neither allocatable, pointer, polymorphic, nor optional92 b = reduce(a, f7)93 !ERROR: Arguments of OPERATION= procedure of REDUCE() must be both scalar of the same type as ARRAY=, and neither allocatable, pointer, polymorphic, nor optional94 b = reduce(a, f8)95 !ERROR: Arguments of OPERATION= procedure of REDUCE() must be both scalar of the same type as ARRAY=, and neither allocatable, pointer, polymorphic, nor optional96 b = reduce(a, f9)97 !ERROR: If either argument of the OPERATION= procedure of REDUCE() has the ASYNCHRONOUS, TARGET, or VALUE attribute, both must have that attribute98 b = reduce(a, f10a)99 !ERROR: If either argument of the OPERATION= procedure of REDUCE() has the ASYNCHRONOUS, TARGET, or VALUE attribute, both must have that attribute100 b = reduce(a, f10b)101 !ERROR: If either argument of the OPERATION= procedure of REDUCE() has the ASYNCHRONOUS, TARGET, or VALUE attribute, both must have that attribute102 b = reduce(a, f10c)103 !ERROR: IDENTITY= must be present when the array is empty and the result is scalar104 b = reduce(a(1:0,:), f)105 !ERROR: IDENTITY= must be present when the array is empty and the result is scalar106 b = reduce(a(1:0, 1), f, dim=1)107 !ERROR: IDENTITY= must be present when DIM=1 and the array has zero extent on that dimension108 c = reduce(a(1:0, :), f, dim=1)109 !ERROR: IDENTITY= must be present when DIM=1 and the array has zero extent on that dimension110 c = reduce(a(1:0, :), f, dim=1)111 !ERROR: IDENTITY= must be present when DIM=2 and the array has zero extent on that dimension112 c = reduce(a(:, 1:0), f, dim=2)113 c(1:0) = reduce(a(1:0, 1:0), f, dim=1) ! ok, result is empty114 c(1:0) = reduce(a(1:0, 1:0), f, dim=2) ! ok, result is empty115 !ERROR: MASK= has no .TRUE. element, so IDENTITY= must be present116 b = reduce(a, f, .false.)117 !ERROR: MASK= has no .TRUE. element, so IDENTITY= must be present118 b = reduce(a, f, reshape([(j > 100, j=1, 100)], shape(a)))119 b = reduce(a, f, reshape([(j == 50, j=1, 100)], shape(a))) ! ok120 !ERROR: OPERATION= argument of REDUCE() must be a pure function of two data arguments121 b = reduce(a, bad_reduce)122 end subroutine123 subroutine not_errors124 type(pdt(10)) :: a(10), b125 b = reduce(a, f11) ! check no bogus type incompatibility diagnostic126 end subroutine127end module128