Parameterized derived-type contained procedure failure

@nedanator ,

Please note what the semantics of the Fortran standard require with arrays is type parameter conformity among the elements of the array. Now note there are two type parameters: the so-called kind-type parameter and the length-type parameter. Each element of an array shall have the same kind-type and/or length-type parameters, as applicable to the type in question. So my point above re: “jagged arrays” refers to this aspect of the standard vis-a-vis your PDT that has a length-type parameter.

To understand this more broadly, a good example is the CHARACTER intrinsic type. See this thread. So one can write in Fortran:

..
   integer, parameter :: CK = selected_char_kind('ISO_10646')
  ..
   character(kind=CK, len=*), parameter :: string = CK_'𨉟呐㗂越'
..

So here, note the named constant string has a kind-parameter of CK corresponding to ISO 10646 character set and it has a length-parameter that corresponds to the length required by the processor (compiler) to hold the supplied string literal which is technically in Vietnamese but as represented by the UTF-8 encoding.

Thus if you are creating an array of strings using the CHARACTER intrinsic type, each element of the array shall have the same kind and length.

But now, note the ALLOCATABLE aspect is not a type parameter, rather it involves different semantics pertaining to an attribute of the type component of a derived type or an object (variable) in a program. Thus the use of the so-called wrapper derived type with type components of the ALLOCATABLE attribute is a workaround to have jagged arrays. So with workaround, each element of the array is of the same type i.e., the wrapper derived type. And since this wrapper type has no type parameters, the standard semantics with type parameter conformity is not an issue. That is not the case when you use a parameterized derived type design since such a type has type parameters.

1 Like