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,628d2a493f1e203d X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!news4.google.com!news.glorb.com!newsfeed2.easynews.com!newsfeed1.easynews.com!easynews.com!easynews!news-out.readnews.com!news-xxxfer.readnews.com!not-for-mail Date: Wed, 26 Jul 2006 10:15:37 -0400 From: "Peter C. Chapin" User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Subtype conformance... not what I was expecting. References: <44c6db66$0$2928$4d3efbfe@news.sover.net> <1153901187.9300.17.camel@localhost.localdomain> In-Reply-To: <1153901187.9300.17.camel@localhost.localdomain> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <44c77904$0$2917$4d3efbfe@news.sover.net> Organization: SoVerNet (sover.net) NNTP-Posting-Host: a4e5ade8.news.sover.net X-Trace: DXC=AESP\8de7MG?LifWAfoK_BK6_LM2JZB_C_D`nC@WjE7G:WUUlR<856OZ[5fVo[S`ZM Georg Bauhaus wrote: > procedure Check is > subtype Above_Zero is Integer range 1 .. 95; -- from liquid to for tea > subtype Below_Zero is Integer range -100 .. -5; -- really solid > > type Frozen_Ptr is access function(X: Below_Zero) return Integer; > type Liquid_Ptr is access function(X: Above_Zero) return Integer; > > function Whirl(Para: Integer) return Above_Zero is > begin > return Para; > end; > > function Cut(Para: Integer) return Below_Zero is > begin > return Para; > end; > > G: Frozen_Ptr := Whirl'access; > Ice: Below_Zero; > begin > Ice := G(0); > end Check; In the statement Ice := G(0) you are assigning an Integer to a Below_Zero. Naturally a runtime check would be necessary to verify the constraint and Constraint_Error would be raised if there was a violation. It's no different than Hot : Integer := 1000; ... Ice := Hot; > I won't want to deliver hot water to/from a function that needs/returns > cold ice. In my view, this will be a contract violation, in this case > at least. G accesses a function returning Integer. Putting Whirl'Access into G is safe because Whirl can't return anything that would violate G's contract. What you subsequently do with what G returns is another matter. Peter