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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Bob Duff Newsgroups: comp.lang.ada Subject: Re: SPARK: missing case value Date: Fri, 09 Oct 2015 10:39:01 -0400 Organization: A noiseless patient Spider Message-ID: <87twq09ke2.fsf@theworld.com> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="ac11a35aadf635436bedb61baed87c73"; logging-data="32708"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/i5a19xmUhkhNtx688Zl62" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:i8tPN2Uy6aXCKv7gvRyvgiR4Mok= sha1:phwOhwa5qDNiAUT/qlheRsskkus= Xref: news.eternal-september.org comp.lang.ada:27947 Date: 2015-10-09T10:39:01-04:00 List-Id: Maciej Sobczak writes: > Consider: > > type Enum is (A, B, C); > > procedure Test (E : in Enum) > with Pre => E /= C > is > begin > case E is > when A => null; > when B => null; > end case; > end Test; That's illegal Ada, as you noted. And illegal SPARK. But this works: type Enum is (A, B, C); subtype A_C is Enum with Predicate => A_C /= B; procedure Test (E : in A_C) is begin case E is when A => null; -- "when B" is not needed. when C => null; end case; end Test; And that has the advantage that A_C need not be a subrange; it can have holes. I find that predicates are often better than preconditions, because the same precondition often applies to many parameters, and also to local variables. The predicate allows you to avoid repetition. ("Predicate =>" is a GNAT-specific extension. In Ada, you need to say "Static_Predicate =>". IMHO the "Static_" part is just noise, but I couldn't convince the rest of ARG.) - Bob