| 1 | ! audit31 harvest: using a derived-type function result INLINE — i.e. |
| 2 | ! `add_t(a, b)%x` in a PRINT statement rather than first assigning |
| 3 | ! the call to a variable — printed zero components because |
| 4 | ! Expr::ComponentAccess's base resolver didn't know how to lower a |
| 5 | ! FunctionCall base. resolve_component_base handled only Name and |
| 6 | ! ComponentAccess, so the fallback const_i32(0) kicked in. Add a |
| 7 | ! `callee_return_derived_type_name` helper and teach the |
| 8 | ! ComponentAccess arm in lower_expr_full to lower the call and use |
| 9 | ! its result pointer as the component base when the callee returns a |
| 10 | ! derived type. Task #481. |
| 11 | ! CHECK: assigned: 4 6 |
| 12 | ! CHECK: inline : 4 6 |
| 13 | program audit31_derived_fn_inline |
| 14 | implicit none |
| 15 | type :: t |
| 16 | integer :: x = 0, y = 0 |
| 17 | end type |
| 18 | type(t) :: a, b, c |
| 19 | a%x = 1; a%y = 2 |
| 20 | b%x = 3; b%y = 4 |
| 21 | c = add_t(a, b) |
| 22 | print *, 'assigned:', c%x, c%y |
| 23 | print *, 'inline :', add_t(a, b)%x, add_t(a, b)%y |
| 24 | contains |
| 25 | function add_t(a, b) result(r) |
| 26 | type(t), intent(in) :: a, b |
| 27 | type(t) :: r |
| 28 | r%x = a%x + b%x |
| 29 | r%y = a%y + b%y |
| 30 | end function |
| 31 | end program |
| 32 |