comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Type of the target of an assignment shall not be abstract
Date: Mon, 15 Feb 2010 16:59:51 -0800 (PST)
Date: 2010-02-15T16:59:51-08:00	[thread overview]
Message-ID: <fbc13ca9-5967-42f4-8efd-b423672c3dab@z10g2000prh.googlegroups.com> (raw)
In-Reply-To: 39f56354-a2e2-4133-bbad-9343b2f22119@k6g2000prg.googlegroups.com

On Feb 15, 9:05 am, Adam Beneschan <a...@irvine.com> 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 ?
>
> >   procedure Init(
> >     xl        : in out Excel_Out_Stream'Class;
> >     format    :        Excel_type:= Default_Excel_type
> >   )
> >   is
> >     dummy_xl_with_defaults: Excel_Out_File;
> >   begin
> >     -- Check if we are trying to re-use a half-finished object
> > (ouch!):
> >     if xl.is_created and not xl.is_closed then
> >       raise Excel_Stream_Not_Closed;
> >     end if;
> >     dummy_xl_with_defaults.format:= format;>>> Excel_Out_Stream(xl):= Excel_Out_Stream(dummy_xl_with_defaults);
>
> >   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) := <something>;

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




  parent reply	other threads:[~2010-02-16  0:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-14 14:20 Type of the target of an assignment shall not be abstract Gautier write-only
2010-02-14 17:57 ` Dmitry A. Kazakov
2010-02-15 17:05 ` Adam Beneschan
2010-02-15 19:00   ` Hibou57 (Yannick Duchêne)
2010-02-23 21:19     ` Robert A Duff
2010-02-16  0:59   ` Adam Beneschan [this message]
2010-02-16 10:03     ` Gautier write-only
2010-02-16 12:14       ` Gautier write-only
2010-02-16 16:12       ` Adam Beneschan
2010-02-28 17:00 ` Gautier write-only
replies disabled

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