comp.lang.ada
 help / color / mirror / Atom feed
From: "Yannick Duchêne (Hibou57)" <yannick_duchene@yahoo.fr>
Subject: Re: Dynamically tagged expression not allowed. Why?
Date: Thu, 03 Jun 2010 04:36:12 +0200
Date: 2010-06-03T04:36:12+02:00	[thread overview]
Message-ID: <op.vdpdimfiule2fv@garhos> (raw)
In-Reply-To: hu45hk$3g8$1@munin.nbi.dk

Le Wed, 02 Jun 2010 01:36:17 +0200, Randy Brukardt <randy@rrsoftware.com>  
a écrit:
> You have to explicitly use a
> type conversion here:
>
>     Conn : Class_Type := Class_Type (New_Class_Instance);
>
This one is not legal, as Class_Type is limited and conversion are not  
allowed on limited type due to their copy based semantic.
[ARM 2005 4.6] says about type conversions
“Neither the target type nor the operand type shall be limited”

> to specify that you want to truncate the returned object, or make the  
> object
> classwide:
>
>    Conn : Class_Type'Class := New_Class_Instance;
That is a beautiful one (to my eyes)


> But notice that while both of these are legal, they'll both raise
> Program_Error because an access-before-elaboration error (the body of
> New_Class_Instance hasn't been elaborated at the point of this call).
Not necessarily, as he can move the body of the function returning  
Class_Type before the declaration of the variable initialized from this  
function.

Instead of


    function New_Class_Instance return Class_Type'Class;

    Conn : Class_Type := New_Class_Instance;

    function New_Class_Instance return Class_Type'Class is
    begin
       -- Just a stub
       return New_Class_Instance;
    end New_Class_Instance;


Simply do


    function New_Class_Instance return Class_Type'Class;

    function New_Class_Instance return Class_Type'Class is
    begin
       -- Just a stub
       return New_Class_Instance;
    end New_Class_Instance;

    Conn : Class_Type := New_Class_Instance;

and everything will go fine.

-- 
There is even better than a pragma Assert: a SPARK --# check.
--# check C and WhoKnowWhat and YouKnowWho;
--# assert Ada;
--  i.e. forget about previous premises which leads to conclusion
--  and start with new conclusion as premise.



  reply	other threads:[~2010-06-03  2:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-29 17:36 Dynamically tagged expression not allowed. Why? Marc A. Criley
2010-05-29 18:23 ` Dmitry A. Kazakov
2010-06-03  2:37   ` Yannick Duchêne (Hibou57)
2010-06-03  7:48     ` Dmitry A. Kazakov
2010-06-01 23:36 ` Randy Brukardt
2010-06-03  2:36   ` Yannick Duchêne (Hibou57) [this message]
2010-06-03  7:57     ` Dmitry A. Kazakov
2010-06-03  8:21       ` Yannick Duchêne (Hibou57)
2010-06-03 16:03     ` Adam Beneschan
2010-06-05 18:47   ` Marc A. Criley
replies disabled

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