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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,c3f4071dbfa958f,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!209.197.12.246.MISMATCH!nx02.iad01.newshosting.com!newshosting.com!198.186.194.250.MISMATCH!news-xxxfer.readnews.com!textspool1.readnews.com!news-out.readnews.com!postnews3.readnews.com!not-for-mail Message-Id: <4c1cf6a3$0$30803$4d3efbfe@news.sover.net> From: "Peter C. Chapin" Subject: Question about SPARK flow error. Newsgroups: comp.lang.ada Date: Sat, 19 Jun 2010 12:58:41 -0400 User-Agent: KNode/0.10.9 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit Organization: SoVerNet (sover.net) NNTP-Posting-Host: b8b56caf.news.sover.net X-Trace: DXC=Id=`TQI2X2ARZfJoa3=8@NK6_LM2JZB_C1DQjNV`m[ZE3?@`i3kGa5K5[BWj4dijcKnT6[ClFS`KN X-Complaints-To: abuse@sover.net Xref: g2news2.google.com comp.lang.ada:12790 Date: 2010-06-19T12:58:41-04:00 List-Id: My example isn't complete enough to compile, but I could work up a complete example if necessary. Hopefully this will be accurate and complete enough... Consider the following procedure: procedure Add_Item (Item : in Some_Type; Index : out Index_Type) is Found : Boolean; begin Found := False; -- Let's see if the Item already exists in the storage. for I in Index_Type range Index_Type'First .. Size loop if Storage(I) = Item then Index := I; -- It does. Return the current position. Found := True; exit; end if; end loop; if not Found then -- The Item does not already exist. Install it in the next slot. Storage(Next_Index) := Item; Index := Next_Index; -- Return where we installed it. -- Play around with Size and Next_Index to set them up for next time -- (not shown). end if; end Add_Item; SPARK gives me an error, "Flow Error 602 - The undefined initial value of Index may be used in the derivation of Index." I understand this to mean that there is a path through the procedure where Index (being an out parameter) is never given a value. So SPARK might be thinking, "Okay... the loop might run to completion without ever setting Index inside the inner conditional statement. Then it might skip over the next conditional statement and thus never set Index at all." However, if I'm not mistaken that can't actually happen. If the conditional statement inside the loop never runs, Found will still be False and the second conditional will definitely execute. Index will receive a value either inside the loop or later. Am I missing something or is this reasoning outside of the abilities of SPARK's flow analysis? Is there some other idiomatic way I should be handling this sort of situation? Thanks Peter