1

I have a module which defines a Type, with its methods, plus some other Type-unrelated methods as well.

module TypeDef
   type, public :: T
     ...
     contains
     ...
     procedure type_proc
   end type
   
   ...
   contains !module
   
    
   subroutine type_proc( this, ... )
      class(T), target :: this
      ...
      call gen_proc( arg_1, arg_n-1, this, arg_n+1 )
      ...
   end subroutine type_proc

   ...

   subroutine gen_proc( arg_1, ..., arg_n-1, tv, arg_n+1 )
      ! this is a general module routine.
      ! NOT type related
      implicit none
      ...
      class(T), pointer, intent(in) :: tv
      ...
      if ( cond ) tv%member = 0
      ...
   end subroutine gen_proc
end module
   

At a given point, I call, from a variable type(T), public :: var its member method type_proc(), which at its interior calls a general module procedure gen_proc(). In there, for some conditions, I may need to change some member(s) of the ACTUAL object calling the method's tree (i.e. var). To do so, I pass this as a constant pointer to call gen_proc() to have its address passed at the function call, and access its members.

But, I get the error as described.

Same if I pass it by reference and not as a const pointer.

I cannot see if I do something mistakenly. Here Intel Fortran error #6633: The type of the actual argument differs from the type of the dummy argument there's something similar, but there, the call happens in a different program unit.

EDIT 2:

Ok, this compiled and run as expected..

module test

   type, public :: T

      real, allocatable :: m1(:)
      real, allocatable :: m2(:)
      integer :: may_change

      contains

      procedure :: t_proc
      procedure :: all_t
   end type

   private :: all_t


   contains



   subroutine t_proc( this, n )
      implicit none
      class(T), target :: this
      integer, intent(in) :: n

      call this%all_t( n )
      call gen_proc( n, this%m1, this%m2, this )
   end subroutine t_proc



   subroutine all_t( this, n )
      implicit none
      class(T) :: this
      integer, intent(in) :: n

      allocate( this%m1( n ) )
      allocate( this%m2( n ) )
   end subroutine

   


   subroutine gen_proc( n, m1, m2, Tt )
      implicit none
      integer, intent(in) :: n
      real, intent(in) :: m1(n), m2(n)
      class(T), intent(in), pointer :: Tt

      if ( .true. ) Tt%may_change = 1
      print *, ' may change = ', Tt%may_change
   end subroutine gen_proc
end module test



module varmod

   use test

   type(T), public :: var
end module varmod




program main
   
   use varmod, only: var
   implicit none
   integer, parameter :: n = 2

   var%may_change = 0
   call var%t_proc( n )
end program main

So, even more than before, I don't know what could be wrong on the actual code...

mEm
  • 353
  • 3
  • 12
  • You really should show the actual cíde without any `...` elipses. And with all types declared. – Vladimir F Героям слава Nov 21 '21 at 13:41
  • Fortran isn't C, and "const pointer" makes no sense. Please expand on what you are trying to do, and show real code (see [mre]). – francescalus Nov 21 '21 at 13:45
  • I add an edit. I cannot put the whole code, since it's more the 1k lines.. hope this gives the idea. – mEm Nov 21 '21 at 14:04
  • Also, as francescalus asks, it'll be a lot easier to answer your question if you give a minimal reproducible example. Your edit adds code which still can't be compiled (so not reproducible), and contains a lot of unnecessary details (so not minimal). Creating a minimal reproducible example takes a little effort, but will likely get you much better responses :) – veryreverie Nov 21 '21 at 14:27
  • 1
    Thanks @veryreverie. However, it is `intent(in), pointer`, which mean that the dummy argument `wd` in `gen_proc()` cannot change reference (i.e. `target`) within the procedure, but it can change `target`'s attributes. Without `intent(in)`, it does not compile to prevent this if the actual argument is not a pointer itself. But still, it does not solve the problem. – mEm Nov 21 '21 at 14:29
  • 1
    @veryreverie you're welcome. In the meantime I try to build an example, and post it as soon as possible – mEm Nov 21 '21 at 14:34
  • If you just get rid of all the `arg_i` and `...` in your first example, does it still exhibit the same problem? Because then you basically have a minimal example ready to go – veryreverie Nov 21 '21 at 14:35
  • A working example is now available. However, it works how I would like, no errors here, so at this point is even more difficult to get what's wrong in the actual version. – mEm Nov 21 '21 at 15:03
  • 2
    A working example, that does not show the error, is almost useless for identifying the error. It is necessary for the error to be reproducible, to be able to reason about it in some useful way or to explain it. We often request a minimal *reproducible* example. It should reproduce the error. Yes, creating such a reproducer is often hard work. – Vladimir F Героям слава Nov 21 '21 at 15:38

0 Answers0