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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,1be082612b8c5f2e X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,UTF8 Path: g2news2.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!usenet-fr.net!gegeweb.org!aioe.org!not-for-mail From: =?utf-8?Q?Yannick_Duch=C3=AAne_=28Hibou57?= =?utf-8?Q?=29?= Newsgroups: comp.lang.ada Subject: Re: Dynamically tagged expression not allowed. Why? Date: Thu, 03 Jun 2010 04:36:12 +0200 Organization: Ada At Home Message-ID: References: NNTP-Posting-Host: si1wcqmfPAlDmjwCD+0L/g.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: Quoted-Printable X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 User-Agent: Opera Mail/10.53 (Win32) Xref: g2news2.google.com comp.lang.ada:12206 Date: 2010-06-03T04:36:12+02:00 List-Id: Le Wed, 02 Jun 2010 01:36:17 +0200, Randy Brukardt = a =C3=A9crit: > You have to explicitly use a > type conversion here: > > Conn : Class_Type :=3D 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 =E2=80=9CNeither the target type nor the operand type shall be limited=E2= =80=9D > to specify that you want to truncate the returned object, or make the = = > object > classwide: > > Conn : Class_Type'Class :=3D 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 :=3D 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 :=3D 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.