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!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Elaboration in generic package Date: Wed, 12 Apr 2017 20:30:17 +0100 Organization: A noiseless patient Spider Message-ID: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="682c98a4d35252288a400e9cf449e523"; logging-data="15457"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18gEx64qmeoTGyZBTNLZzRJnA1lm/Rlj5Y=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (darwin) Cancel-Lock: sha1:qT+WiHBb7e3n7nk0RlYkfJeOUas= sha1:g3Ol7pWnfvQI7gcNcfJTS7jQ6+E= Xref: news.eternal-september.org comp.lang.ada:46580 Date: 2017-04-12T20:30:17+01:00 List-Id: A StackOverflow user raises this problem (http://stackoverflow.com/q/43349462/40851). The code: generic Top_M : Positive; package Mystic is type T is private; procedure Info; private type Table is array (Positive range <>) of Positive; function reallyComplicatedFunction(x : Positive) return Table; mytable : constant Table := reallyComplicatedFunction(top_m); --<<<<< -- I will need mytable for calculations later type T is array (mytable'Range) of Natural; -- T is very different from Table, except they share their Range end Mystic; They wonder how the call to reallyComplicatedFunction at line 10 succeeds, given it looks like its body hasn't been seen yet (ARM 3.11(10)). Indeed, if I make Mystic non-generic (Top_M is a constant) GNAT tells me kryptozoon.ada:12:33: warning: cannot call "reallyComplicatedFunction" before body seen kryptozoon.ada:12:33: warning: Program_Error will be raised at run time and then, sure enough, raised PROGRAM_ERROR : kryptozoon.ada:12 access before elaboration Is it possible that the answer is ARM 3.11(13), "For the instantiation of a generic unit that has a body, a check is made that this body is already elaborated."? If so, this seems surprising.