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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,10b4863a0a2cf267 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!z10g2000prh.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Type of the target of an assignment shall not be abstract Date: Mon, 15 Feb 2010 16:59:51 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <770863d9-14ae-4a05-b924-2dfeda7a96a8@f15g2000yqe.googlegroups.com> <39f56354-a2e2-4133-bbad-9343b2f22119@k6g2000prg.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1266281991 4159 127.0.0.1 (16 Feb 2010 00:59:51 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 16 Feb 2010 00:59:51 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: z10g2000prh.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:9261 Date: 2010-02-15T16:59:51-08:00 List-Id: On Feb 15, 9:05=A0am, Adam Beneschan wrote: > > A question for the RM hermeneutists. > > The instruction marked below with ">>>" goes well through one Ada 95 > > compiler (GNAT with -gnat95) but is not accepted by another one > > (ObjectAda 7.2.2). > > Which compiler is right ? > > > =A0 procedure Init( > > =A0 =A0 xl =A0 =A0 =A0 =A0: in out Excel_Out_Stream'Class; > > =A0 =A0 format =A0 =A0: =A0 =A0 =A0 =A0Excel_type:=3D Default_Excel_typ= e > > =A0 ) > > =A0 is > > =A0 =A0 dummy_xl_with_defaults: Excel_Out_File; > > =A0 begin > > =A0 =A0 -- Check if we are trying to re-use a half-finished object > > (ouch!): > > =A0 =A0 if xl.is_created and not xl.is_closed then > > =A0 =A0 =A0 raise Excel_Stream_Not_Closed; > > =A0 =A0 end if; > > =A0 =A0 dummy_xl_with_defaults.format:=3D format;>>> Excel_Out_Stream(x= l):=3D Excel_Out_Stream(dummy_xl_with_defaults); > > > =A0 end Init; > > > >>> excel_out.adb: Error: line 595 col 5 LRM:3.9.3(8), The type of the = target of an assignment shall not be abstract > > This is indeed illegal, although offhand I'm not sure it should be. FYI, I asked about this on Ada-Comment, and got a response from Randy. Making this legal would be a problem, since there's a possibility that the abstract type has an abstract Adjust routine. If the assignment on the abstract view were allowed (even though it's an abstract "view conversion" of an object with a concrete type), it would be possible that a nonexistent Adjust routine would be called, and that sort of thing is prohibited by the language. On the other hand, it's probably a problem even if the type isn't abstract. If you use a view conversion on the left side of an assignment T2(X) :=3D ; and T2 is a controlled type, and X's type is a type derived from T2, then an Adjust will be called on just the "T2" portion of X but this Adjust won't affect any other component of the type extension. IMHO, there's a good chance that this will not produce the desired result. The same is true if T2(X) is passed as an OUT or IN OUT parameter to some procedure, and the procedure assigns to the parameter as a whole. Unfortunately, it's probably too late to fix Ada to prevent things like this, or to allow things like this in an abstract case. My own recommendation: If you want the 14 components of the abstract type Excel_Out_Stream to be treated as a unit, then make them a unit--- i.e. define a record type with 14 components, and then Excel_Out_Stream would have just one component of that record type. Of course, that decision probably has to be made when the package is first written; making that change now would require changing how all those components are accessed everywhere else in the program. Barring that, you can either write 14 assignment statements and hope the compiler is smart enough to optimize them, or you can use a "trick" like Dmitry's suggestion, which will "work" but (in my opinion) doesn't help set up a type structure that accurately reflects the concepts in your program. -- Adam