[patch, fortran] PR36355: fix argument type checking for matmul

Tobias Burnus burnus@net-b.de
Wed May 28 16:22:00 GMT 2008


Daniel Franke wrote:
> Updated patch attached, not regression tested yet.
>   
Still NOT OK. It is valid to mix two numeric types, e.g. integer + real 
(result: real), or real + complex (result: complex):

print *, matmul(a,b)
               1
Error: Argument types of 'matmul' intrinsic at (1) must match 
(INTEGER(4)/REAL(4))

You need to test:

if (matrix_a->ts.type != matrix_b->ts.type
|| (gfc_numeric_ts (&matrix_a->ts) && gfc_numeric_ts (&matrix_b->ts))


Besides: I don't like your error message. I'd prefer "must be the same" 
otherwise the text in the parentheses is misleading. However, in our 
case this is not the right choice either. Other compilers use:

"Error: Data type mismatch in arguments to MATMUL intrinsic" (NAG f95)

Which looks ok, here one could append a ": %s and %s" or " (%s/%s)".

Alternative (based on g95/gfortran old output):
"Error: Argument of 'matmul' intrinsic at (1) must be all numeric or all 
logical"
(the "%s..." type stuff could also be added)

ifort:
Error: Logical and numeric arguments must not be mixed.

Tobias

PS: When you create a final patch, please include also test cases for 
valid and invalid code.



More information about the Fortran mailing list