2017-08-17 16:36 GMT+02:00, Anton Shterenlikht <[log in to unmask]>:
> I think this module is conforming:
>
> module m
> type :: t( l )
> integer, len :: l=30
> contains
> procedure :: s
> end type t
> contains
> subroutine s( a )
> class( t ) :: a
> end subroutine s
> end module m
>
> One compiler rejects it with:
>
> All length type parameters of the passed object dummy argument must be
> assumed. [A]
> subroutine s( a )
> ----------------^
>
> Indeed I can change
> class( t ) :: a
> to
> class( t( l=*) ) :: a
> and this makes the compiler happy,
> but I think this is unnecessary given
> that type t gives length parameter l
> a default value.
Just curious: what would be the use of this code? The idea is that
given any variable
type(t) :: my_t
I can call my_t%s() no matter what the value of my_t%l is. Having
a type bound procedure which only works for the default value would
break this, right?
The following case is different:
> Also, if I remove a type-bound procedure:
>
> module m
> type :: t( l )
> integer, len :: l=30
> ! contains
> ! procedure :: s
> end type t
> contains
> subroutine s( a )
> class( t ) :: a
> end subroutine s
> end module m
>
> then this is acceptable to the compiler too.
since now the subroutine is not bound to all the objects of class(t):
the user must judge whether a call s(my_t) makes sense or not.
Thanks,
Marco
|