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!feeder.eternal-september.org!news.uzoreto.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Is this a bug? Date: Mon, 30 Dec 2019 20:41:07 +0200 Organization: Tidorum Ltd Message-ID: References: <1d96e0e1-7700-4947-9fcb-051a1203c703@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net q1N5LnLev8tTRQiH0y/t9QXgQUsRmitNF2KKdUK6XmT4i1RqOz Cancel-Lock: sha1:9nu6sE7/RazLnY8XXY9aYBNPFOQ= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 In-Reply-To: <1d96e0e1-7700-4947-9fcb-051a1203c703@googlegroups.com> Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:57775 Date: 2019-12-30T20:41:07+02:00 List-Id: On 2019-12-30 19:51, Anh Vo wrote: > On Monday, December 30, 2019 at 7:44:37 AM UTC-8, reinert wrote: >> Hello, >> >> assume the following Ada procedure: >> ------------------------------------------------------------------------------ >> with Text_IO; >> procedure test1 is >> package test_package is >> type rec1_t is tagged record >> a : integer := 2; >> -- b : integer := 2; >> end record; >> function a(x : rec1_t) return integer is (3); >> rec1 : rec1_t; >> end test_package; >> begin >> Text_IO.Put(" test_package.rec1: " & integer'image(test_package.rec1.a)); >> end test1; >> ------------------------------------------------------------------------------- >> >> It gives (for mye computer): >> >> test_package.rec1: 2 >> >> If I change the statement >> >> "a : integer := 2;" >> >> to >> >> "b : integer := 2;" >> >> then I get: >> >> test_package.rec1: 3 >> >> Is this reasonable? Bug? >> >> reinert > > No, the compiler behaves correctly. In fact, if tagged record is > replaced by record, the latter case will be rejected. Yes. When rec1_t is tagged, the "selected component" text "test_package.rec1.a" could refer either to the rec1_t-component "a" or to the subprogram (function) "a". In RM 4.1.3(9.1/2) and RM 4.1.3(9.2/3), the latter case is available only under the condition that the tagged record type (rec1_t) does not have a (visible) component with the name "a". This means that the ambiguity is resolved in favour of the component "a", which has the value 2. One could ask, why is such an ambiguity not rejected (made illegal)? Probably because such an illegality rule would have made many illegal many Ada programs that were legal before the introduction of the "object.operation" syntax for tagged-record objects. If this is a problem for you, you might check if your compiler has an option to warn about such cases, or if AdaControl can do the same. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .