12-159r2 To: J3 From: Malcolm Cohen Subject: Interp Array constructors with polymorphic values Date: 2012 June 28 Note that this is an alternative formulation of the interp in 12-158. ---------------------------------------------------------------------- NUMBER: F08/0080 TITLE: Array constructors with polymorphic values KEYWORDS: Array constructor, polymorphic DEFECT TYPE: Erratum STATUS: J3 consideration in progress QUESTION: Q1. Consider Program m198_003a Type :: t Real a End Type Type,Extends(t) :: t2 Real b End Type Class(t),Allocatable :: x,y Allocate(x,Source=t2(1,2)) Allocate(y,Source=t(3)) Print *, [ t :: x, y ] End Program Constraint C4105 of the standard, page 85, says "If specifies a derived type, all expressions in the array constructor shall be of that derived type ..." However, although the declared type of X is type T, its dynamic type is type T2. Does this program conform to the standard? Q2. Consider Program m198_003a Type :: t Real a End Type Type,Extends(t) :: t2(n) Integer,Len :: n Real b(n) End Type Class(t),Allocatable :: x,y,z Allocate(x,Source=t2(3)(1,[2,3,4])) Allocate(y,Source=t(5)) Allocate(z,Source=t2(4)(6,7)) Print *, [ x, y ] End Program 4.8 paragraph 2 of the standard says "If is omitted, each expression shall have the same length type parameters; in this case, the declared type and type parameters of the array constructor are those of the expressions." However, although the length type parameters of the declared types of X, Y and Z are the same (all being the empty set), the length type parameters of the dynamic types are not: Y has no dynamic length type parameters, and the value of the dynamic length type parameter N of X and Z are different. Does this program conform to the standard? Q3. Consider Program m198_003c Type,Abstract :: t Real a End Type Type,Extends(t) :: t2 Real b End Type Class(t),Allocatable :: x,y Allocate(x,Source=t2(1,2)) Allocate(y,Source=t2(3,4)) Print *, [ x, y ] End Program This appears to conform to the standard, but the dynamic type of the array constructor is the same as its declared type, and is therefore abstract. Is this intended to conform to the standard? ANSWER: A1. This program was intended to be conforming. An edit is supplied to clarify the standard. A2. This program was intended to be conforming. An edit is supplied to clarify the standard. A3. This program was not intended to be conforming. An edit is supplied to add the necessary requirement to the standard. EDITS: [85:8-9] In 4.8, C4105, Change "all expressions in the shall be of that derived type and" to "the declared type of each expression in the shall be that derived type and". [85:10+] In 4.8, after C4106, insert new constraint "C4106a (R472) The declared type of an shall not be abstract." [85:13-14] In 4.8p2, Change "each expression in the array constructor shall have the same length type parameters;" to "corresponding length type parameters of the declared type of each expression shall have the same value;". SUBMITTED BY: Malcolm Cohen HISTORY: 12-159 m198 F03/0080 submitted 12-159r1 m198 Revised edits. 12-159r2 m198 Fixed typo, passed J3 meeting. ----------------------------------------------------------------------