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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,b672743914db49f,start X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!k79g2000hse.googlegroups.com!not-for-mail From: =?iso-8859-2?q?Tomek_Wa=B3kuski?= Newsgroups: comp.lang.ada Subject: "Ada Gems": Constructor functions Date: Wed, 05 Sep 2007 18:10:27 -0000 Organization: http://groups.google.com Message-ID: <1189015827.384331.17490@k79g2000hse.googlegroups.com> NNTP-Posting-Host: 83.26.85.39 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" X-Trace: posting.google.com 1189015827 24872 127.0.0.1 (5 Sep 2007 18:10:27 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 5 Sep 2007 18:10:27 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; pl; rv:1.8.1.6) Gecko/20070801 Firefox/2.0.0.6,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: k79g2000hse.googlegroups.com; posting-host=83.26.85.39; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0 Xref: g2news2.google.com comp.lang.ada:1759 Date: 2007-09-05T18:10:27+00:00 List-Id: Hi, motivated by this article posted at adacore.com I have written some code: --------- t.ads --------- with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; package T is type Object (<>) is tagged limited private; function Create_Object (Name : in String) return Object; function Construct return Object; function Name (This : in Object) return String; type Object is tagged limited record Name : Unbounded_String; end record; end T; --------- t.adb --------- package body T is function Create_Object (Name : in String) return Object is return (Name => To_Unbounded_String (Name)); end Create_Object; function Construct return Object is return Create_Object (Name => "Object without a name!"); end Construct; function Name (This : in Object) return String is begin return To_String (This.Name); end Name; type Object is tagged limited record Name : Unbounded_String; end record; end T; --------- test_t.adb --------- with T; procedure Test_T is Some_Object : constant T.Object := Construct; begin null; end Test_T; ------------------------------ ... and tried to compile it. (Gentoo Linux, gnat-gpl-4.1.3.2007) Compiler said: " +================GNAT BUG DETECTED==================+ | GPL 2007 (20070402-41) (i686-pc-linux-gnu) Assert_Failure namet.adb: 687 | (...) compilation abandoned gnatmake: "test_t.adb" compilation error " Is it REALLY a compiler bug? Or am I only dumb? :) Maybe I'm doing something, somewhere wrong?