comp.lang.ada
 help / color / mirror / Atom feed
From: AdaMagica <christ-usch.grein@t-online.de>
Subject: Re: "unconstrained subtype in component declaration" vs "discriminant in constraint must appear alone"
Date: Wed, 24 Feb 2021 01:59:53 -0800 (PST)	[thread overview]
Message-ID: <7a436624-3863-4a0f-a1c5-cf50db419c9cn@googlegroups.com> (raw)
In-Reply-To: <6716a4e5-02ac-4735-83c9-28bff3f8aae6n@googlegroups.com>

0012...@gmail.com schrieb am Dienstag, 23. Februar 2021 um 23:06:19 UTC+1:
> Please help figure out this: 
> 
> type CARDS is new cards_numbers range 1..52; 
> --> 
> 41:10 missing case values: -128 .. 0 
> 41:10 missing case values: 5 .. 127 
> 41:25 subtype of expression is not static, alternatives must cover base type 
> from --> 
> [card in CARDS, of course] 
> case (card / 13) +1 is 
> when 1 => put("Spades"); 
> when 2 =>put("Hearts"); 
> when 3 =>put("Spades"); 
> when 4 =>put("Clovers"); 
> end case; 
> 
> how can the compiler not know that CARD is limited from 1 to 52, including 0 for the base type (type Cards_numbers is range 0..52) 

Because Card/13 + 1 is a value in CARDS, and there is a rule that all values of the type must be covered.
Define a subtype covering only 1..4 and subtype convert the expression, then it shoud be fine.

  reply	other threads:[~2021-02-24  9:59 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-22  0:14 "unconstrained subtype in component declaration" vs "discriminant in constraint must appear alone" Mehdi Saada
2021-02-22  6:32 ` J-P. Rosen
2021-02-22 10:14   ` AdaMagica
2021-02-22 10:57     ` Dmitry A. Kazakov
2021-02-22 14:20       ` Mehdi Saada
2021-02-22 15:11         ` J-P. Rosen
2021-02-22 15:55         ` Dmitry A. Kazakov
2021-02-22 16:21           ` Mehdi Saada
2021-02-23 22:06             ` Mehdi Saada
2021-02-24  9:59               ` AdaMagica [this message]
2021-02-24 10:04               ` Jeffrey R. Carter
2021-02-24 14:11               ` Simon Wright
2021-02-24 15:57               ` Shark8
2021-02-25  0:13                 ` Mehdi Saada
2021-02-25  8:58                   ` AdaMagica
2021-02-25 10:25                     ` Mehdi Saada
2021-02-25 10:28                     ` Mehdi Saada
2021-02-22 10:35 ` Jeffrey R. Carter
2021-02-22 14:21   ` Mehdi Saada
2021-02-22 15:02     ` Jeffrey R. Carter
2021-02-22 15:08       ` J-P. Rosen
replies disabled

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