From: Adam Beneschan <adambeneschan@gmail.com>
Subject: Re: bug or feature
Date: Mon, 8 Sep 2014 08:31:51 -0700 (PDT)
Date: 2014-09-08T08:31:51-07:00 [thread overview]
Message-ID: <62e7cd35-9df9-4d26-ae16-62a8725d1184@googlegroups.com> (raw)
In-Reply-To: <854mwi1om4.fsf@stephe-leake.org>
On Monday, September 8, 2014 1:52:01 AM UTC-7, Stephen Leake wrote:
>
> > 1 with Ada.Text_IO;
> > 2 with Datum_Pkg;
> > 3
> > 4 procedure Main is
> > 5
> > 6 subtype Datum is Datum_Pkg.Datum;
> > 7 subtype Datum_Vector is Datum_Pkg.Datum_Vectors.Vector;
> > 8
> > 9 D_Vec : Datum_Vector;
> > 10
> > 11 begin
> > 12
> > 13 for Dat : Datum_Pkg.Datum of D_Vec loop
> > 14 Ada.Text_IO.Put_Line ("Datum=" & Dat.Image);
> > 15 end loop;
> > 16
> > 17 for Dat : Datum of D_Vec loop
> > 18 Ada.Text_IO.Put_Line ("Datum=" & Dat.Image);
> > 19 end loop;
> > 20
> > 21 end Main;
>
> > Line 13 compiles without message but in line 17 I get an error message:
> > subtype indication does not match element type
> > But this line should be equivalent to line 13 because of the subtype definition
> > in line 6.
>
> line 6 defines a _new_ subtype, _different_ from Datum_Pkg.Datum. They have
> the same base type, but the error message says "subtype", not "base
> type".
>
> So you are out of luck.
>
> In general, a subtype can add constraints, which is why this matters; if
> the loop parameter has different constraints than the container object,
> you'll get runtime errors.
But that doesn't explain why he's getting a *compile-time* error.
As far as I can tell from the RM, you'd get an exception at run-time only if the subtype_indication is more restrictive than the container element *and* if the code actually tries to assign the loop parameter to an element that does not satisfy the subtype constraints. This one looks like a GNAT bug to me.
-- Adam
next prev parent reply other threads:[~2014-09-08 15:31 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-07 10:33 bug or feature Charly
2014-09-07 16:59 ` Dirk Heinrichs
2014-09-08 8:48 ` Stephen Leake
2014-09-08 18:07 ` Charly
2014-09-09 4:32 ` Stephen Leake
2014-09-09 4:39 ` Dirk Heinrichs
2014-09-08 8:51 ` Stephen Leake
2014-09-08 9:09 ` J-P. Rosen
2014-09-08 15:31 ` Adam Beneschan [this message]
2014-09-08 9:43 ` Simon Wright
2014-09-09 4:40 ` Stephen Leake
2014-10-06 17:48 ` Simon Wright
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox