Skip to content

Commit 3692b0f

Browse files
committed
fixed typos and included last feedback
1 parent 6c9e744 commit 3692b0f

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

features/rfc-oop-constructors.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,31 @@ call to the super constructor
474474
- the child type does not need to declare additional discriminant anymore just
475475
for the purpose of setting the parent ones.
476476

477+
With discriminants, you may have situations where components are not available.
478+
In this case, the Initialization list need to only refer to components that are
479+
available for the discriminant provided - a constraint error is to be raised
480+
otherwise. For example:
481+
482+
.. code-block:: ada
483+
484+
type Bla (V : Boolean) is record
485+
case V is
486+
when True =>
487+
A : Integer;
488+
when False =>
489+
B : Integer;
490+
end case;
491+
end record;
492+
493+
procedure Bla'Constructor
494+
with Initialize => (V => True, B => 10); -- Constraint Error
495+
is
496+
null;
497+
end Bla'Constructor;
498+
499+
This is consistent with discriminants used to constrain arrays (the value of the
500+
array would need to match the constrained component).
501+
477502
Subtyping and Discriminants
478503
^^^^^^^^^^^^^^^^^^^^^^^^^^^
479504

features/rfc-oop-dispatching.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,47 @@ different version of the subprogram depending on the context. Note that
211211
this means that subsequent usage of the 'Access attribute may not yield the
212212
same address, which is allowed.
213213

214+
'Specialized
215+
------------
216+
217+
In some situation, in particular in the context of post conditions, we need to
218+
be able to implement "specialization" calls as opposed to dispatching. A
219+
specialized call. A specialized call can only be written on a class wide
220+
post-condition. It is always static, called after the static type of the
221+
parameter. Upon derivation, said postcondition is modified to call the derived
222+
specialized subprogram if any. For example:
223+
224+
.. code-block:: ada
225+
226+
package P is
227+
type Root is tagged null record;
228+
229+
function Is_Init (Self : Root) return Boolean is (True);
230+
231+
procedure Init (Self : out Root) is abstract with
232+
Post'Class => Self'Specialized.Is_Init;
233+
234+
type Child is new Root with record
235+
F : Integer;
236+
end record;
237+
238+
function Is_Init (Self : Child) return Boolean is (Self.F >= 1);
239+
240+
procedure Init (Self : out Child);
241+
-- Also inherits Post => Self'Specialized.Is_Init, but this time statically call the child Is_Init.
242+
end P;
243+
244+
package body P is
245+
246+
procedure Init (Self : out Child) is
247+
begin
248+
Self'Super.Init;
249+
Self.F := 1;
250+
end Init;
251+
252+
end P;
253+
254+
214255
Reference-level explanation
215256
===========================
216257

features/rfc-oop-primitives.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ It is possible to also scope primitives in regular records:
157157
158158
package P is
159159
160-
type R is record
160+
type R is class record
161161
F : Integer;
162162
163163
procedure Prim (Self : in out R; V : Integer);
@@ -245,7 +245,7 @@ E.g:
245245
246246
package body P is
247247
248-
type body R is record
248+
type body R is class record
249249
procedure Prim (Self : in out R; V : Integer) is
250250
begin
251251
Self.F := V;

0 commit comments

Comments
 (0)