J3/02-295 Date: 17 October 2002 To: J3 From: Aleksandar Donev Subject: Selecting the base component of polymorphic objects Reference: J3-007R3, J3/02-294 ______________________________________ Summary ______________________________________ Polymorphic object need to occasionally be used in places where a non-polymorphic object of the base type (I will use this term instead of declared type) is expected. I propose to allow the component selection polymorphic_object%base_type for objects declared with TYPE, EXTENSIBLE :: base_type ... END TYPE ... CLASS(base_type), ... :: polymorphic_object to yield a nonpolymorphic object of type base_type. This simplifies and makes the syntax more consistent. ______________________________________ Motivation ______________________________________ ________________ Inconsistent syntax ________________ Assuming the above declaration of base_type, and TYPE, EXTENDS(base_type) :: extended_type ... END TYPE ... CLASS(extended_type), ... :: another_object the component selection another_object%base_type is valid in Fortran 2002 (54:13-55:3). It is only when another_object is actually declared to be polymorphic of type base_type that such component selection is not allowed. This makes no sense! ________________ Unneccessary complications ________________ There are several places where the object polymorphic_object should be usable as an non-polymorphic object of type base_type: 1. As an actual argument for a dummy declared as TYPE(base_type),... :: dummy_argument This is allowed in F2x by virtue of not being forbidden and is strange and confused me (and likely others) 2. In intrinsic assignment, pointer association, etc. For example: TYPE(base_type), POINTER :: base_pointer CLASS(base_type), TARGET :: polymorphic_object base_pointer=>polymorphic_object This is not allowed in current Fortran 2002 (142:35, C716). ______________________________________ Solution ______________________________________ Every polymorphic variable should have a component named after its base_type, even if it is not of an extended type. So 53:13 should be replaced with (possibly split into two sentences): ``An object of base/extended type has a scalar, nonpointer, nonallocatable, *base/parent component* with the type and type parameters of the base/parent type. The name of this component is the base/parent type name.'' There is the possibility of only allowing such base component selection for polymorphic variables, but I see no reason why not to allow it for nonpolymorphic variables as well (see Note 74: 5.7) ______________________________________ Edits ______________________________________ Other then the edit above, more edits will be needed to add the term base component in places where the term parent component appears. These will only be done after feedback is received. ! EOF