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: 103376,8581da5753cc1105 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.66.76.201 with SMTP id m9mr386015paw.1.1346258692863; Wed, 29 Aug 2012 09:44:52 -0700 (PDT) Received: by 10.68.218.226 with SMTP id pj2mr455261pbc.19.1346258692848; Wed, 29 Aug 2012 09:44:52 -0700 (PDT) Path: t10ni109755722pbh.0!nntp.google.com!r4no3025297pbs.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 29 Aug 2012 09:44:52 -0700 (PDT) In-Reply-To: <48024e68-4d18-4bbc-af47-102f32e4f43e@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ NNTP-Posting-Host: 66.126.103.122 References: <48024e68-4d18-4bbc-af47-102f32e4f43e@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Mystery with "others" From: Adam Beneschan Injection-Date: Wed, 29 Aug 2012 16:44:52 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-08-29T09:44:52-07:00 List-Id: On Wednesday, August 29, 2012 8:38:21 AM UTC-7, (unknown) wrote: > Hello, >=20 >=20 >=20 > I get an error message with the initialization of variable s4 below, that= I don't understand. >=20 > The workaround is easy, using the expression for variable s3. >=20 > Still, I am curious about the reason. >=20 >=20 >=20 > GNAT GPL 2012, with any of the modes Ada 95, 2005 and 2012, I get: >=20 > test_sets.adb:10:21: "others" choice not allowed here >=20 > ObjectAda 7.2.2 (Ada 95 only) is more verbose >=20 > test_sets.adb: Error: line 10 col 17 LRM:4.3.3(11), An OTHERS is not allo= wed in this context because there is no applicable_index_constraint, Contin= uing >=20 >=20 >=20 > So why is Ada unhappy with the expression after "s4 :=3D " ?\ The "or" operator is a function, and the arguments to the function are decl= ared as the *unconstrained* subtype of Set's base type. Set is actually a = constrained subtype of an array that looks like this: type [base-type] is array(Enum range <>) of Boolean; and the function "or" is declared: function "or" (Left, Right : [base-type]) return [base-type]; See 4.5.1(3). You have to understand the distinction between types and sub= types here. Array *types* are unconstrained; subtypes of those types can b= e constrained or unconstrained. When an aggregate like (d =3D> True, others =3D> False) shows up, the langu= age needs to know how to get the bounds, or index constraints (that's what = the phrase "applicable index constraint" in the error message means (see 4.= 3.3). In the declarations of s1 and s2, there's a rule that if the aggrega= te is the expression on the right of :=3D, the variable on the left side wi= ll give the constraint. So those declarations are OK. But when the aggreg= ate is the parameter to a function, and the function parameter doesn't have= any constraints, there's nothing telling it what the constraints are. (*W= e* know that for a predefined function like "or", the constraint of one par= ameter should be the same as the constraint of the other parameter because = "or" needs its parameters to be the same size. But that isn't true for all= functions. So there can't really be a general rule to handle that case.) = Since there's nothing telling it what the bounds are, the compiler has to = reject the aggregate. This will work: s4: Set :=3D s1 or Set'(d =3D> True, others =3D> False); Now the Set' qualifier tells the compiler what the bounds are going to be. -- Adam >=20 > procedure Test_sets is >=20 > type Enum is (a,b,c,d); >=20 > type Set is array(Enum) of Boolean; >=20 > s1: Set :=3D (a =3D> True, others =3D> False); > s2: Set :=3D (d =3D> True, others =3D> False); > s3: Set :=3D s1 or s2; > s4: Set :=3D s1 or (d =3D> True, others =3D> False); -- <- Line 10