From: fedya_fedyakoff@inbox.ru
Subject: Re: Limited returns
Date: Tue, 24 Jun 2008 03:56:19 -0700 (PDT)
Date: 2008-06-24T03:56:19-07:00 [thread overview]
Message-ID: <b10c3cf4-ffbd-4274-9cc5-877f0d8370ac@c65g2000hsa.googlegroups.com> (raw)
In-Reply-To: 3pwjng4q8sde.mh4dkauvjpxt.dlg@40tude.net
> 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)
next prev parent reply other threads:[~2008-06-24 10:56 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-23 14:21 Limited returns Dmitry A. Kazakov
2008-06-23 15:04 ` fedya_fedyakoff
2008-06-23 15:20 ` fedya_fedyakoff
2008-06-23 16:53 ` Dmitry A. Kazakov
2008-06-24 10:56 ` fedya_fedyakoff [this message]
2008-06-24 13:51 ` Dmitry A. Kazakov
2008-06-24 15:01 ` fedya_fedyakoff
2008-06-24 16:31 ` Dmitry A. Kazakov
2008-06-24 16:42 ` Dmitry A. Kazakov
2008-06-23 15:49 ` Adam Beneschan
2008-06-24 10:13 ` fedya_fedyakoff
2008-06-23 15:15 ` Adam Beneschan
2008-06-23 17:03 ` Dmitry A. Kazakov
2008-06-23 18:15 ` Adam Beneschan
2008-06-23 19:44 ` Dmitry A. Kazakov
2008-06-26 12:35 ` Egil Høvik
2008-06-26 14:12 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox