From: Stephen Leake <Stephen.Leake@gsfc.nasa.gov>
Subject: maintenance of overriding subprograms
Date: 1997/09/02
Date: 1997-09-02T00:00:00+00:00 [thread overview]
Message-ID: <340C2EA5.B9F@gsfc.nasa.gov> (raw)
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
next reply other threads:[~1997-09-02 0:00 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-09-02 0:00 Stephen Leake [this message]
[not found] ` <340DCE1D.6C5F@bix.com>
1997-09-04 0:00 ` maintenance of overriding subprograms John G. Volan
1997-09-07 0:00 ` Robert Dewar
1997-09-08 0:00 ` Robert A Duff
1997-09-09 0:00 ` Dan Johnston D.B.
1997-09-09 0:00 ` Tom Moran
1997-09-09 0:00 ` W. Wesley Groleau x4923
1997-09-10 0:00 ` Robert Dewar
1997-09-11 0:00 ` Dan Johnston D.B.
1997-09-12 0:00 ` Robert Dewar
1997-09-12 0:00 ` Richard A. O'Keefe
1997-09-12 0:00 ` Samuel Mize
1997-09-18 0:00 ` Shmuel (Seymour J.) Metz
1997-09-24 0:00 ` John G. Volan
1997-09-25 0:00 ` Shmuel (Seymour J.) Metz
1997-09-26 0:00 ` Richard A. O'Keefe
1997-09-05 0:00 ` Robert Dewar
1997-09-05 0:00 ` Stephen Leake
1997-09-05 0:00 ` Matthew Heaney
1997-09-07 0:00 ` Robert A Duff
1997-09-08 0:00 ` Tom Moran
1997-09-08 0:00 ` Stephen Leake
1997-09-08 0:00 ` W. Wesley Groleau x4923
1997-09-09 0:00 ` Robert A Duff
1997-09-09 0:00 ` Jon S Anthony
1997-09-10 0:00 ` Anonymous
-- strict thread matches above, loose matches on Subject: below --
1997-09-10 0:00 Marc Wachowitz
1997-09-29 0:00 Marin David Condic, 561.796.8997, M/S 731-96
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox