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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,33ed4ca582c945fc X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!c65g2000hsa.googlegroups.com!not-for-mail From: fedya_fedyakoff@inbox.ru Newsgroups: comp.lang.ada Subject: Re: Limited returns Date: Tue, 24 Jun 2008 03:56:19 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <304d62f5-53eb-4ec2-bcd5-a84ac8f9fe60@m44g2000hsc.googlegroups.com> <3pwjng4q8sde.mh4dkauvjpxt.dlg@40tude.net> NNTP-Posting-Host: 81.25.167.50 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1214304980 17417 127.0.0.1 (24 Jun 2008 10:56:20 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 24 Jun 2008 10:56:20 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c65g2000hsa.googlegroups.com; posting-host=81.25.167.50; posting-account=ESyqEgoAAAB5AfqBmmLVjrqeNSkFQsKY User-Agent: G2/1.0 X-HTTP-UserAgent: Opera/9.50 (Windows NT 5.1; U; ru),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:834 Date: 2008-06-24T03:56:19-07:00 List-Id: > Even if it could, that would not make the program illegal. The compiler > could only warn you about a possible exception propagation, which is not an > error. Well, I thought the compiler must warn about possible exception, especially when there is such a possibility. Ok, this is just my opinion, but returning to our rams - some strangeness (an error?) is still there - consider: --- named.ads package Named is type Object is interface; function name(this: Object) return String is abstract; end Named; --- some.ads with Named; with Ada.Finalization; use Ada.Finalization; with Ada.Strings.Bounded; package Some is Size : constant := 80; package bs is new Ada.Strings.Bounded.Generic_Bounded_Length(Size); use bs; type Object is new Controlled and Named.Object with private; function Create( name: String ) return Object; overriding procedure Initialize(this: in out Object); overriding procedure Finalize(this: in out Object); overriding procedure Adjust(this: in out Object); overriding function name(this: Object) return String; private type Object is new Controlled and Named.Object with record the_name: Bounded_String; end record; end Some; --- some.adb with ada.Text_IO; with system; package body Some is package tio renames ada.Text_IO; function Create( name: String ) return Object is begin return O : Object do O.the_name := To_Bounded_String(name); end return; end Create; procedure Initialize(this: in out Object) is begin tio.Put_Line("Initialization " & this.name ); end Initialize; procedure Finalize(this: in out Object) is begin tio.Put_Line("Finalization " & this.name); end Finalize; procedure Adjust(this: in out Object) is begin tio.Put_Line("Ajusting " & this.name); end Adjust; function name(this: Object) return String is begin return To_String(this.the_name); end name; end Some; --- factory.ads with Named; package Factory is function Create(name: String) return Named.Object'Class; end Factory; --- factory.adb with Ada.Strings.Fixed; use Ada.Strings.Fixed; with Some; package body Factory is function Create(name: String) return Named.Object'Class is begin return Some.Create(name); end; end Factory; --- boom.adb with ada.Text_IO; with Named; use Named; with Factory; procedure boom is package tio renames ada.Text_IO; aNamed: Named.Object'Class := Factory.create("Some1"); begin aNamed := Factory.create("Some1"); --- *** tio.put_line( "My name is " & aNamed.name ); tio.Flush; end boom; What I can't figure out is why it's crashed at *** ? Factory creates two fully equivalent objects of the same type! Program's output looks very strange as well (at least for me) - why for two initialization we have five (!!!) finalization? It drives me crazy! The program output is as follows: Initialization Ajusting Some1 Finalization Some1 Ajusting Some1 Initialization Ajusting Some1 Finalization Some1 Finalization Some1 Finalization Some1 Finalization Some1 Execution terminated by unhandled exception Exception name: CONSTRAINT_ERROR Message: boom.adb:10 tag check failed Call stack traceback locations: 0x401b69 0x401676 0x401235 0x401286 0x7c816d4d [2008-06-24 14:51:09] process exited with status1 (elapsed time: 00.14s)