From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,896d86ef3723978c,start X-Google-Attributes: gid103376,public From: Stephen Leake Subject: maintenance of overriding subprograms Date: 1997/09/02 Message-ID: <340C2EA5.B9F@gsfc.nasa.gov>#1/1 X-Deja-AN: 269807398 Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA Reply-To: Stephen.Leake@gsfc.nasa.gov Newsgroups: comp.lang.ada Date: 1997-09-02T00:00:00+00:00 List-Id: The discussion of maintaining separate spec and implementation reminded me of a potential maintenance problem with overriding subprograms of derived types. Suppose we have: package Root is type Root_Type is tagged private; procedure Create (Item : in out Root_Type); private type Root_Type is tagged record Count : Integer; end record; end Root; package body Root is procedure Create (Item : in out Root_Type) is begin Item.Count := 0; end Create; end Root; package Derived is type Derived_Type is new Root.Root_Type with private; -- override Create (Root_Type) procedure Create (Item : in out Derived_Type); private type Derived_Type is new Root.Root_Type with record Leaves : Integer; end record; end Derived; package body Derived is procedure Create (Item : in out Derived_Type) is begin Root.Create (Root.Root_Type (Item)); Item.Leaves := 0; end Create; end Derived; Now suppose that in maintenance we add a parameter to Root.Create: procedure Create (Item : in out Root_Type; Max : in Integer := 0); When we compile, the compiler tells us that the package body of Root does not have a corresponding body for Create. However, it does not tell us that Derived.Create no longer overrides Root.Create; Derived.Create silently changes from an overriding subprogram to a "normal" subprogram. To solve this, perhaps we could add a pragma: pragma Confirm_Override ({subprogram_name}); which would generate a compile-time error if {subprogram_name} does not override a root type subprogram. In Ada 200x, we could use the keyword "new" for this: new procedure Create (...); which would have the same effect. Any comments? -- - Stephe