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,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!transit3.readnews.com!news-out.readnews.com!not-for-mail Date: Tue, 25 Jul 2006 23:02:56 -0400 From: "Peter C. Chapin" User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Subtype conformance... not what I was expecting. Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <44c6db66$0$2928$4d3efbfe@news.sover.net> Organization: SoVerNet (sover.net) NNTP-Posting-Host: f2761eb1.news.sover.net X-Trace: DXC=lj:?L[9Y;>KI\??^0ATCVDK6_LM2JZB_Cln?^cLlkdbC:WUUlR<856OBgfE;dUgT5Gh=T=HC<6aDF X-Complaints-To: abuse@sover.net Xref: g2news2.google.com comp.lang.ada:5925 Date: 2006-07-25T23:02:56-04:00 List-Id: I'm experimenting with Ada's handling of access to subprogram types. I was surprised to discover that the following example does not work (I'm using GNAT GPL 2006): procedure Check is subtype Narrow is Integer range -10..10; type Function_Ptr is access function(X : Narrow) return Integer; function F(Para : Integer) return Narrow is begin return Para; end F; G : Function_Ptr := F'Access; Result : Integer; begin Result := G(0); end Check; The compiler complains about the initialization of G with F'Access saying that it is not "subtype conformant." However, I believe this initialization would be type safe. Since F's argument types are super types of G's argument types, there is no context where G can be called that would violate the constraints on the underlying arguments of F. Similarly since F's return type is a subtype of G's return type, anything F might return would be acceptable as a return from G. I assumed that this was what subtype conformance was about, but apparently not. In fact, GNAT appears to require the argument and return subtypes to match exactly. However, this seems overly restrictive. I'm curious about the rationale for this restriction. Peter