comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Static bounds of loop - compilation error
Date: Tue, 30 Oct 2012 09:10:54 -0700 (PDT)
Date: 2012-10-30T09:10:54-07:00	[thread overview]
Message-ID: <36d9f85f-6daa-4b0b-84b9-1a28d24da2b0@googlegroups.com> (raw)
In-Reply-To: <6cc8e815-96c3-4a79-8bcd-e3aea906b889@googlegroups.com>

On Tuesday, October 30, 2012 6:26:09 AM UTC-7, pascal....@gmail.com wrote:
> Hi Ada experts,
> 
> can anyone explain the following compilation errors:
> 
> procedure T is
>   type E is (A, B, C);
>   subtype S is E range A .. B;
>   X, Y : S;
> begin
>   X := A;
>   Y := B;
>   for I in S range X .. Y loop
>     case I is
>       when A => null;
>       when B => null;
>     end case;
>   end loop;
> end T;
> 
> >> missing case value: "C"
> 
> A similar example where S is a subtype of Positive leads to the same  error and also: bounds of "I" are not static, alternatives must cover base type
> 
> Indeed, X and Y are not static but the bounds of S are, and all the values of S are covered in the "case".
> 
> So is it a bug?

No.  RM 5.4 gives three rules for how the values of a CASE must be covered, based on the "nominal subtype" of the expression (in this case, the name I).  If the subtype is static and constrained, then everything in the subtype has to be covered; otherwise, everything in the *base range* has to be covered.  (The third rule has to do with universal integers and doesn't apply here.)  Here, I's subtype is not static, so therefore that rule doesn't apply, and the only rule left is the rule that everything in the base range has to be covered--which means everything in E.  There aren't any rules to handle a case like you've coded, where I's subtype is non-static but there's another subtype involved (because if the "S" in "S range X .. Y"); I think that adding language rules for this would mean that I has yet another kind of subtype associated with it, in addition to the "actual" and "nominal" subtypes, which would probably make things too complicated.

Saying either

  case S(I) is

or

  case S'(I) is

should make things work, because now the CASE expression has a nominal subtype S, which is static, rather than "S range X .. Y", which isn't.

                         -- Adam



  parent reply	other threads:[~2012-10-30 16:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-30 13:26 Static bounds of loop - compilation error pascal.malaise
2012-10-30 14:37 ` Georg Bauhaus
2012-10-30 16:10 ` Adam Beneschan [this message]
2012-10-30 17:03   ` Yannick Duchêne (Hibou57)
2012-10-30 17:15     ` Yannick Duchêne (Hibou57)
2012-10-31 13:18       ` Marc C
2012-10-31 16:23 ` pascal.malaise
replies disabled

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