Issue 181353
Summary [flang] rejection of valid code related to finalizers
Labels flang
Assignees
Reporter hmenke
    Flang rejects the following valid code. This code is accepted by GFortran, ifort, ifx, and NAG.

No finalization happens inside of `inner_set`, so I believe the error about `finalize` being impure is incorrect.

```fortran
module types_m
  implicit none (type, external)

  type impure_t
  contains
 final :: finalize
  end type impure_t

  type inner_t
    type(impure_t) :: impure
  contains
    procedure :: set => inner_set
  end type inner_t

  type outer_t
    type(inner_t) :: inner
  end type outer_t
contains
  subroutine finalize(this)
    type(impure_t), intent(inout) :: this
    ! whatever
  end subroutine finalize

  pure subroutine inner_set(this)
    class(inner_t), intent(inout) :: this
  end subroutine inner_set

  pure subroutine outer_set(outer)
 type(outer_t), intent(inout) :: outer
    call outer%inner%set()
  end subroutine outer_set
end module types_m

program test
  use types_m, only: outer_t, outer_set
  implicit none (type, external)
  type(outer_t) :: outer
  call outer_set(outer)
end program test
```

```
error: Semantic errors in test.F90
./test.F90:30:5: error: Actual argument associated with INTENT(IN OUT) dummy argument 'this=' is not definable
 call outer%inner%set()
      ^^^^^^^^^^^^^^^^^^^^^^
./test.F90:30:5: because: 'inner' has an impure FINAL procedure 'finalize'
      call outer%inner%set()
      ^^^^^^^^^^^^^^^^^^^^^^
./test.F90:16:22: Declaration of 'inner'
      type(inner_t) :: inner
 ^^^^^
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to