From: Jere <jhb.chat@gmail.com>
Subject: Full view of a private partial view cannot be a subtype
Date: Sat, 2 Dec 2017 18:14:48 -0800 (PST)
Date: 2017-12-02T18:14:48-08:00 [thread overview]
Message-ID: <c6ba70e3-bfd0-42ca-b742-dc472965eea0@googlegroups.com> (raw)
Say I have some type:
package Base is
type Instance is tagged limited private;
procedure Operation(Object : in out Instance);
private
type Instance is tagged limited null record;
procedure Operation(Object : in out Instance) is null;
end Base;
It might have 20 or so operations, but this is a simplified
example. There are times where in another package I want to
subtype Base.Instance and do renames of the operations in order
to bring them all into scope (or whatever the correct term is):
package New_Type1 is
subtype Instance is Base.Instance;
procedure Operation(Object : in out Instance);
private
procedure Operation(Object : in out Instance) renames Base.Operation;
end New_Type1;
(NOTE: is there a better way to do this?)
This is all well and good, but sometimes while I as an implementer
want this kind of relationship, I don't necessarily want to expose
that relationship outside the private section of a package. Here I
run into a problem as I cannot (as far as I can tell) do:
package New_Type2 is
type Instance is tagged limited private;
procedure Operation(Object : in out Instance);
private
subtype Instance is Base.Instance;
procedure Operation(Object : in out Instance renames Base.Operation;
end New_Type2;
as it fails with an error ("Instance" not type conformant with declaration)
on the subtype line.
Instead I have to do (again, unless there is a better way):
package New_Type2 is
type Instance is tagged limited private;
procedure Operation(Object : in out Instance);
private
type Instance is new Base.Instance with null record;
end New_Type2;
package body New_Type2 is
procedure Operation(Object : in out Instance) is
begin
Base.Instance(Object).Operation;
end Operation;
end New_Type2;
This might be ok, but it's a lot of noise added (I now
need a body for all of my operations and need to type
convert parameters and any return values). I'm also not
sure the semantics between the method I wanted and the
method I had to use are the same (in all situations). I.E.
I don't know if
procedure Operation(Object : in out Instance renames Base.Operation;
has the same semantics as
procedure Operation(Object : in out Instance) is
begin
Base.Instance(Object).Operation;
end Operation;
My instinct says they do not. That may be ok, but I am
just unsure.
So I guess my question is two part:
1. Is there a way to make the full view of a private type
a subtype when the partial view is not a subtype? Or am
I forced to derive a new type?
2. If it isn't possible, are there any language reasons for
why that must be so? Would making a full view of a type
actually a subtype under the hood break something?
next reply other threads:[~2017-12-03 2:14 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-03 2:14 Jere [this message]
2017-12-03 12:01 ` Full view of a private partial view cannot be a subtype Jeffrey R. Carter
2017-12-03 13:33 ` Jere
2017-12-03 14:34 ` Jeffrey R. Carter
2017-12-03 17:44 ` Robert Eachus
2017-12-03 18:50 ` Simon Wright
2017-12-03 22:10 ` Robert Eachus
2017-12-03 19:03 ` Jeffrey R. Carter
2017-12-03 22:23 ` Jere
2017-12-04 8:25 ` Dmitry A. Kazakov
2017-12-04 18:04 ` Jeffrey R. Carter
2017-12-04 20:41 ` Jere
2017-12-04 21:48 ` Jeffrey R. Carter
2017-12-05 8:20 ` Dmitry A. Kazakov
2017-12-05 18:16 ` Jeffrey R. Carter
2017-12-05 20:39 ` Dmitry A. Kazakov
2017-12-05 21:38 ` Jeffrey R. Carter
2017-12-05 12:35 ` Jere
2017-12-05 18:40 ` Jeffrey R. Carter
2017-12-06 12:54 ` Jere
2017-12-06 18:03 ` Jeffrey R. Carter
2017-12-05 20:22 ` Randy Brukardt
2017-12-05 15:27 ` Shark8
2017-12-05 18:50 ` Jeffrey R. Carter
2017-12-05 20:59 ` Randy Brukardt
2017-12-05 22:43 ` Shark8
2017-12-07 0:52 ` Randy Brukardt
2017-12-05 20:16 ` Randy Brukardt
2017-12-05 21:29 ` Jeffrey R. Carter
2017-12-07 0:04 ` Randy Brukardt
2017-12-04 20:49 ` Randy Brukardt
2017-12-05 12:56 ` Jere
2017-12-05 20:12 ` Randy Brukardt
2017-12-17 15:26 ` Jere
2017-12-17 15:39 ` Dmitry A. Kazakov
2017-12-18 22:47 ` Randy Brukardt
2017-12-19 1:22 ` Jere
2017-12-19 23:16 ` Randy Brukardt
2017-12-19 1:01 ` Jere
2017-12-19 9:08 ` Dmitry A. Kazakov
2017-12-19 13:08 ` Jere
2017-12-19 13:27 ` Dmitry A. Kazakov
2017-12-19 19:10 ` Stephen Leake
2017-12-18 20:45 ` Stephen Leake
2017-12-18 22:54 ` Randy Brukardt
2017-12-19 1:08 ` Jere
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox