| 1 | ! Chained user-defined operator: `a + b + c` resolves the inner |
| 2 | ! `a + b` to a vec_add call returning a derived type, then the |
| 3 | ! outer `+ c` must dispatch through the same operator interface. |
| 4 | ! Audit-level: catches the case where the BinaryOp lowering's |
| 5 | ! intermediate result type prevents the outer overload from |
| 6 | ! matching (it should match because the result is still a vec). |
| 7 | ! CHECK: 6.0000000E0 |
| 8 | module chain_op |
| 9 | implicit none |
| 10 | type :: vec |
| 11 | real :: x |
| 12 | end type |
| 13 | interface operator(+) |
| 14 | module procedure vec_add |
| 15 | end interface |
| 16 | contains |
| 17 | type(vec) function vec_add(a, b) |
| 18 | type(vec), intent(in) :: a, b |
| 19 | vec_add%x = a%x + b%x |
| 20 | end function |
| 21 | end module |
| 22 | program t |
| 23 | use chain_op |
| 24 | implicit none |
| 25 | type(vec) :: a, b, c, r |
| 26 | a%x = 1.0 |
| 27 | b%x = 2.0 |
| 28 | c%x = 3.0 |
| 29 | r = a + b + c |
| 30 | print *, r%x |
| 31 | end program |
| 32 |