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!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!newsfeed.xs3.de!io.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: making a son benefit access ton an instanciation of a generic package required as a formal parameter to his father and instanciated by him Date: Mon, 22 Jan 2018 19:33:54 -0600 Organization: JSA Research & Innovation Message-ID: References: <193126c2-f171-43ed-8c7c-00570f1dd4d4@googlegroups.com><1eb1f57d-36fa-4bf0-8a40-5b32d71e5c28@googlegroups.com> Injection-Date: Tue, 23 Jan 2018 01:33:54 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="4426"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader02.eternal-september.org comp.lang.ada:50063 Date: 2018-01-22T19:33:54-06:00 List-Id: "Simon Wright" wrote in message news:ly8tcp28nv.fsf@pushface.org... > "J-P. Rosen" writes: > >> Right, and there is a good reason. >> Assuming exception E is declared in generic package GP1: >> >> Imagine this: >> generic >> package P1 is new GP1 (<>); >> package P2 is new GP1 (<>); >> package GP2 is... end GP2; >> >> package body GP2 is >> ... >> begin >> exception >> when P1.E => -- not allowed by Ada >> ... >> when P2.E => -- not allowed by Ada >> ... >> end GP2; >> >> So far, so good. But then, if you instantiate: >> package Inst1 is new GP1; >> >> package Inst2 is new GP2 (Inst1, Inst1); >> >> then you would end up with two different handlers for the same >> exception (since formals P1 and P2 are actually the same package >> Inst1). And > > This doesn't seem a million miles away from having name clashes caused > by use-visibility. > > Agreed, the _instantiation_ must fail. Ah, but remember the "language-lawyer" message I wrote a few minutes ago. Ada enforces Legality Rules in the body in an "assume-the-worst" manner. Thus, if any possible instantiation would cause a failure, it is illegal in a generic body. This was done to make the contract model of generics sensible. If one can compile a generic body, then the body is always legal for an instantation. This allows sane separate compilation, where the body doesn't necessarily exist when the instantation is compiled. If the instantiation proves legal when compiled, it will stay that way regardless of what is in the body. Otherwise, you would have the legality of instantiations changing when a body is changed, meaning that you would be getting errors in far off compilation units. Some compilers do in fact do pure macro substitutions, and give the effect of proper separate compilation by compiling the instances during binding. This is OK and not noticable to a user, because those instances have to be legal (modulo compiler bugs, of course). If a compiler worked this way without the assume-the-worst rules, you'd get lots of error messages at bind time, long after you thought you had a clean compile. That would be annoying at best. Randy.