A question to the EP experts? Is the following program valid EP, and if so, what should its output be?
program Foo (Output);
type i23 = 2 .. 3 value 2; a = record b: Integer value 1; case c: i23 of 2: (d: Integer value 4); 3: (e: Integer value 5) end value [b: 6; case c: 3 of [e: 7]];
var v: ^a;
begin New (v, 2); WriteLn (v^.b, ' ', v^.c, ' ', v^.d) end.
: 6.7.5.3 Dynamic allocation procedures : : The domainÂtype of the newÂpointerÂtype denoting the type possessed by p : shall contain a typeÂidentifier, which shall denote the recordÂtype, the : bindability, and except as otherwise noted below, the initial state of the : created variable. : : The caseÂconstant c 1 shall correspond to the variantÂpart of the : fieldÂlist of the recordÂtype. For 1 < i <= n, c i shall correspond to the : variantÂpart of the fieldÂlist of the variantÂdenoter denoting the variant : specified by c i Â1. For 1 <= i <= n, the variantÂpart corresponding to c i : shall closestÂcontain a tagÂtype. For 1 <= i <= n, the initial state of the : selector of the variant corresponding (see above) with the caseÂconstant c : i shall be the state bearing the value associated (see 6.4.3.4) with the : variant corresponding (see 6.4.3.4) to the value denoted by c i . : : It shall be an error if a variant of a variantÂpart within the new variable : is active and a different variant of the variantÂpart is one of the : specified variants. : : NOTE --- 1 Since the initial state of each selector is determined by the : corresponding caseÂconstant, any corresponding tagÂfield is also attributed : the value of the caseÂconstant (see 6.4.3.4).
According to the first paragraph v^.b must be 6 IIUIC (i.e., the initial state of the record, not of the field, prevails).
According to paragraphs 2 and 4, v^.c must be 2 which should be quite clear.
But what about v^.d? AFAICS, paragraphs 2 and 4 don't state it, so according to the first paragraph, it would have the initial state it has in the type a. But in a, the second variant is active, so field d is undefined.
Does this mean that indeed v^.d is undefined after `New' (despite specifying initial values wherever possible, i.e. *omitting* the initial state of a would result in v^.d being defined)? Or did I overlook some reason it is defined (in this case, presumably, as 4)?
Or is this `New' statement invalid? If anything, paragraph 3 might be a reason, but AFAICS it's meant to forbid invalid combinations of selectors in nested variant records, and doesn't apply here.
The more general question is whether the initial states of the components of a structured type can have any influence when the structured type itself has a `value' specification. (Since I don't see another way how they could.)
Frank