comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Dynamically tagged expression required
Date: Thu, 8 Dec 2005 15:52:06 +0100
Date: 2005-12-08T15:52:06+01:00	[thread overview]
Message-ID: <19rt1tv1y2lu0$.1j7v8bh48fwby.dlg@40tude.net> (raw)
In-Reply-To: dn9dnd$d5h$1@sunnews.cern.ch

On Thu, 08 Dec 2005 14:50:37 +0100, Maciej Sobczak wrote:

> procedure Hello is
> 
>     type Shape is tagged null record;
>     type Triangle is new Shape with
>       record
>          SideLen : Positive;
>       end record;
> 
>     A : Shape;
>     B : Shape'Class := A;             -- (1)
>     C : Triangle := (SideLen => 7);
> 
> begin
> 
>     A := C;                           -- (2)
>     B := C;                           -- (3)
> 
> end Hello;
> 
> (2) does not compile, and this is what was expected.
> (3) does not compile, neither, beucase "dynamically tagged expression 
> required".
> 
> Interestingly, (1) is fine.
> 
> Why is (1) allowed?

It is not an assignment, but initialization.

> Why is (3) not allowed?

B := B; -- Legal
B := Shape'Class (A); -- Legal
B := Shape'Class (C); -- Legal, but raises Constraint_Error

You cannot change the tag of a class-wide object, so it would have little
sense anyway. However if ":=" were considered as a dispatching operation,
then (3) should be made legal.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  parent reply	other threads:[~2005-12-08 14:52 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-08 13:50 Dynamically tagged expression required Maciej Sobczak
2005-12-08 14:46 ` Georg Bauhaus
2005-12-08 14:52 ` Dmitry A. Kazakov [this message]
2005-12-08 19:17 ` Martin Krischik
2005-12-09  9:09   ` Maciej Sobczak
2005-12-09 12:05     ` Jean-Pierre Rosen
2005-12-09 16:41     ` Robert A Duff
2005-12-09 20:18       ` Martin Krischik
2005-12-11  0:43         ` Matthew Heaney
2005-12-11 11:45           ` Martin Krischik
2005-12-11 14:24             ` Matthew Heaney
2005-12-11 15:18               ` Martin Krischik
2005-12-11 18:07             ` Matthew Heaney
2005-12-12 19:16               ` Martin Krischik
2005-12-13 20:43                 ` Georg Bauhaus
2005-12-13 21:00                   ` Georg Bauhaus
2005-12-09 20:41       ` Randy Brukardt
2005-12-09 20:16     ` Martin Krischik
2005-12-11  0:46       ` Matthew Heaney
2005-12-12  9:44       ` Maciej Sobczak
2005-12-12 19:13         ` Martin Krischik
2005-12-14 10:22           ` Maciej Sobczak
2005-12-15 20:10             ` Martin Krischik
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox