To: J3 J3/23-108 From: Van Snyder Subject: Extensible enumeration types Date: 2023-January-14 Reference: 22-007r1, 23-106 1. Introduction =============== Paper 23-106 proposes and explains a block-structured exception handling system for Fortran. It proposes that there should be exceptions enumerated in an enumeration type EXCEPTIONS defined in the intrinsic module ISO_Fortran_Env, for each of the run-time conditions that the standard requires processors to detect. Detection of these exceptions should always be enabled. It further proposes that there should be additional exceptions, for which detection can be enabled by the program, to report other violations such as subscripts out of bounds or improper arguments for intsinsic procedures, such as a negative argument to SQRT. Those further exceptions are identified by enumerators of a type OPTIONAL_EXCEPTIONS, also defined in the intrinsic module ISO_Fortran_Env. It is proposed that that type be an extension of the type EXCEPTIONS. Why an extension? Because 23-106 proposes that the device used to enable exceptions specifies the exceptions using identifiers of enumerators of enumeration type EXCEPTIONS or an extension of that type. This includes user-defined exceptions. Paper 23-106 notes that a proposal for extensible enumeration types would appear in a separate paper. This is that paper. 2. Additional use cases ======================= One simple example of an additional use of extensibile enumeration types is a COLOR type having enumerators RED, BLUE, and GREEN, an extension type RAINBOW having, in addition, colors VIOLET, ORANGE, and YELLOW, and a further extension LINGERIE with, in addition, colors MAUVE, TAUPE, and ECRU. 3. Proposal =========== 3.1 Syntax ---------- In addition to in (R767 in 22-007r1), allow EXTENDS ( ) with a constraint that shall be the name of an accessible enumeration type. There is no provision for type-bound procedures. There is no provision for polymorphic variables of enumeration types. 3.2 Semantics ------------- An enumeration type that is an extension of another enumeration type inherits the enumerators of its parent type, as if they were declared first in the definition, in the same order they appear in the definition of the parent type. For example, the enumerators of RAINBOW type are as if the enumerators RED, BLUE, and GREEN were declared in its definition, in that order, before the declaration of the enumerators VIOLET, ORANGE, and YELLOW. 3.3 Constructor --------------- The enumeration constructor (R771 and 7.6.2p5 in 22-007r1) is extended to allow an enumerator of the type (which might be an inherited enumerator) as its argument. Thereby, the enumerator RED can be considered to be an enumerator of the type RAINBOW using the constuctor RAINBOW(RED). This is necessary for argument association and generic resolution. 3.4 Type compatibility ---------------------- Existing rules for type compatibility apply, without change.