1 ! RUN: %python %S/test_errors.py %s %flang_fc1
2 ! Invalid operand types when user-defined operator is available
7 logical function eq_tt(x
, y
)
9 type(t
), intent(in
) :: x
, y
13 logical function add_tr(x
, y
)
15 type(t
), intent(in
) :: x
18 logical function plus_t(x
)
20 type(t
), intent(in
) :: x
22 logical function add_12(x
, y
)
23 real, intent(in
) :: x(:), y(:,:)
26 interface operator(.and
.)
27 logical function and_tr(x
, y
)
29 type(t
), intent(in
) :: x
33 interface operator(//)
34 logical function concat_tt(x
, y
)
36 type(t
), intent(in
) :: x
, y
39 interface operator(.not
.)
40 logical function not_r(x
)
51 subroutine test_relational()
61 !ERROR: Operands of .EQ. must have comparable types; have CHARACTER(KIND=1) and INTEGER(4)
63 !ERROR: Operands of .EQ. must have comparable types; have INTEGER(4) and CHARACTER(KIND=1)
65 !ERROR: Operands of .EQ. must have comparable types; have LOGICAL(4) and INTEGER(4)
67 !ERROR: Operands of .EQ. must have comparable types; have INTEGER(4) and LOGICAL(4)
69 !ERROR: Operands of .EQ. must have comparable types; have TYPE(t) and REAL(4)
72 lVar
= z
'a' == b
'1010' !OK
74 subroutine test_numeric()
76 !ERROR: No intrinsic or user-defined OPERATOR(+) matches operand types REAL(4) and TYPE(t)
79 subroutine test_logical()
81 !ERROR: No intrinsic or user-defined OPERATOR(.AND.) matches operand types REAL(4) and TYPE(t)
84 subroutine test_unary()
86 !ERROR: No intrinsic or user-defined OPERATOR(+) matches operand type LOGICAL(4)
89 !ERROR: No intrinsic or user-defined OPERATOR(.NOT.) matches operand type TYPE(t)
92 subroutine test_concat()
94 !ERROR: No intrinsic or user-defined OPERATOR(//) matches operand types TYPE(t) and REAL(4)
97 subroutine test_conformability(x
, y
)
98 real :: x(10), y(10,10)
100 !ERROR: No intrinsic or user-defined OPERATOR(+) matches rank 2 array of REAL(4) and rank 1 array of REAL(4)
105 ! Invalid operand types when user-defined operator is not available
114 subroutine test_relational()
115 !ERROR: Operands of .EQ. must have comparable types; have TYPE(t) and REAL(4)
117 !ERROR: Subroutine name is not allowed here
118 l
= r
== test_numeric
119 !ERROR: Function call must have argument list
122 subroutine test_numeric()
123 !ERROR: Operands of + must be numeric; have REAL(4) and TYPE(t)
126 subroutine test_logical()
127 !ERROR: Operands of .AND. must be LOGICAL; have REAL(4) and TYPE(t)
130 subroutine test_unary()
131 !ERROR: Operand of unary + must be numeric; have LOGICAL(4)
133 !ERROR: Operand of .NOT. must be LOGICAL; have TYPE(t)
136 subroutine test_concat(a
, b
)
137 character(4,kind
=1) :: a
138 character(4,kind
=2) :: b
140 !ERROR: Operands of // must be CHARACTER with the same kind; have CHARACTER(KIND=1) and CHARACTER(KIND=2)
142 !ERROR: Operands of // must be CHARACTER with the same kind; have TYPE(t) and REAL(4)
145 subroutine test_conformability(x
, y
)
146 real :: x(10), y(10,10)
147 !ERROR: Operands of + are not conformable; have rank 2 and rank 1
152 ! Invalid untyped operands: user-defined operator doesn't affect errors
154 interface operator(+)
155 logical function add(x
, y
)
156 logical, intent(in
) :: x
164 integer, pointer :: px
168 !ERROR: Operands of + must be numeric; have untyped and COMPLEX(4)
171 !ERROR: Operand of unary - must be numeric; have untyped
173 !ERROR: Operands of + must be numeric; have LOGICAL(4) and untyped
175 !ERROR: A NULL() pointer is not allowed as an operand here
177 !ERROR: A NULL() pointer is not allowed as a relational operand
178 l
= null(px
) /= null(px
)
179 !ERROR: A NULL() pointer is not allowed as an operand here
181 !ERROR: A NULL() pointer is not allowed as an operand here
183 !ERROR: A NULL() pointer is not allowed as a relational operand
185 !ERROR: A NULL() pointer is not allowed as an operand here
190 ! Test alternate operators. They aren't enabled by default so should be
191 ! treated as defined operators, not intrinsic ones.
194 subroutine s1(x
, y
, z
)
197 !ERROR: No operator .A. defined for REAL(4) and REAL(4)
199 !ERROR: No operator .O. defined for REAL(4) and REAL(4)
201 !ERROR: No operator .N. defined for REAL(4)
203 !ERROR: No operator .XOR. defined for REAL(4) and REAL(4)
205 !ERROR: No operator .X. defined for REAL(4)
210 ! Like m4 in resolve63 but compiled with different options.
211 ! .A. is a defined operator.
213 interface operator(.A
.)
214 logical function f1(x
, y
)
215 integer, intent(in
) :: x
, y
218 interface operator(.and
.)
219 logical function f2(x
, y
)
220 real, intent(in
) :: x
, y
224 subroutine s1(x
, y
, z
)
227 !ERROR: No intrinsic or user-defined OPERATOR(.AND.) matches operand types COMPLEX(4) and COMPLEX(4)
229 !ERROR: No intrinsic or user-defined .A. matches operand types COMPLEX(4) and COMPLEX(4)
234 ! Type-bound operators
238 procedure
, pass(x
) :: p1
=> f1
239 generic
:: operator(+) => p1
241 type, extends(t1
) :: t2
243 procedure
, pass(y
) :: p2
=> f2
244 generic
:: operator(+) => p2
248 procedure
, nopass
:: p1
=> f1
249 !ERROR: OPERATOR(+) procedure 'p1' may not have NOPASS attribute
250 generic
:: operator(+) => p1
253 integer function f1(x
, y
)
254 class(t1
), intent(in
) :: x
255 integer, intent(in
) :: y
257 integer function f2(x
, y
)
258 class(t1
), intent(in
) :: x
259 class(t2
), intent(in
) :: y
261 subroutine test(x
, y
, z
)
268 !ERROR: Operands of + must be numeric; have CLASS(t2) and CLASS(t1)
270 !ERROR: Operands of + must be numeric; have INTEGER(4) and CLASS(t1)
275 ! Some cases where NULL is acceptable - ensure no false errors
281 generic
:: operator(/) => s1
283 interface operator(-)
287 integer function s1(x
, y
)
288 class(t1
), intent(in
) :: x
289 class(t1
), intent(in
), pointer :: y
292 integer function s2(x
, y
)
293 type(t1
), intent(in
), pointer :: x
, y
298 type(t1
), pointer :: x1
300 ! These cases are fine.
302 j
= x1
- null(mold
=x1
)
303 j
= null(mold
=x1
) - null(mold
=x1
)
304 j
= null(mold
=x1
) - x1
306 j
= x1
/ null(mold
=x1
)
307 j
= null() - null(mold
=x1
)
308 j
= null(mold
=x1
) - null()
310 !ERROR: A NULL() pointer is not allowed as an operand here
311 j
= null() / null(mold
=x1
)
312 !ERROR: A NULL() pointer is not allowed as an operand here
313 j
= null(mold
=x1
) / null()
314 !ERROR: A NULL() pointer is not allowed as an operand here
325 subroutine s1(ip1
, rp1
)
326 integer, pointer, intent(in
) :: ip1
327 real, pointer, intent(in
) :: rp1
329 subroutine s2(rp2
, ip2
)
330 real, pointer, intent(in
) :: rp2
331 integer, pointer, intent(in
) :: ip2
334 integer, pointer :: ip
336 call generic(ip
, rp
) ! ok
337 call generic(ip
, null()) ! ok
338 call generic(rp
, null()) ! ok
339 call generic(null(), rp
) ! ok
340 call generic(null(), ip
) ! ok
341 call generic(null(mold
=ip
), null()) ! ok
342 call generic(null(), null(mold
=ip
)) ! ok
343 !ERROR: One or more actual arguments to the generic procedure 'generic' matched multiple specific procedures, perhaps due to use of NULL() without MOLD= or an actual procedure with an implicit interface
344 call generic(null(), null())
354 procedure(integer) :: jf
357 procedure(real) :: af
360 external underspecified
361 !ERROR: One or more actual arguments to the generic procedure 'generic' matched multiple specific procedures, perhaps due to use of NULL() without MOLD= or an actual procedure with an implicit interface
362 call generic(underspecified
)
366 ! Ensure no bogus errors for assignments to CLASS(*) allocatable
373 class(*), allocatable
:: poly
376 poly
= 'Il faut imaginer Sisyphe heureux'