comp.lang.ada
 help / color / mirror / Atom feed
From: AdaMagica <christ-usch.grein@t-online.de>
Subject: GNAT bug with assertions
Date: Fri, 10 Aug 2018 03:29:32 -0700 (PDT)
Date: 2018-08-10T03:29:32-07:00	[thread overview]
Message-ID: <a9ceb787-b964-4c53-91de-02bee039f6e5@googlegroups.com> (raw)

I would have expected that predicates are also checked on return values as they are checked on parameters.
In the following test, no exception is raised on call of funcction Wrong although it returns a value not fulfilling the predicate.

Is this a GNAT bug or my wrong expectation?

package Pack is

  type Priv is private;
  C: constant Priv;

  function Test (X: Priv) return Boolean;
  subtype Subt is Priv with Dynamic_Predicate => (Test (Subt));

  function Wrong return Subt;
  function Good (X: Subt) return Boolean;

private

  type Priv is new Integer;
  C: constant Priv := -1;

  function Test (X: Priv) return Boolean is (X > 0);

  function Wrong return Subt is (-1);
  function Good (X: Subt) return Boolean is (True);

end Pack; 

with Ada.Assertions, Ada.Text_IO;
use  Ada.Assertions, Ada.Text_IO;

with Pack;
use  Pack;

procedure Test_Pack is
begin

  begin
    Put_Line (Good (C)'Image);
  exception
    when Assertion_Error =>
      Put_Line ("Good (C) raises Assertion_Error => OK");
  end;

  declare
    X: Priv;
  begin
    X := Wrong;
    Put_Line ("Assertion_Error expected by calling Wrong => KO");
  exception
    when Assertion_Error =>
      Put_Line ("Wrong raises Assertion_Error => OK");
  end;

end Test_Pack;

             reply	other threads:[~2018-08-10 10:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-10 10:29 AdaMagica [this message]
2018-08-10 14:23 ` GNAT bug with assertions Anh Vo
2018-08-10 15:16 ` Jacob Sparre Andersen
2018-08-10 16:16   ` Simon Wright
2018-08-10 20:42     ` Randy Brukardt
2018-08-12 18:35       ` AdaMagica
2018-08-12 18:51         ` Simon Wright
2018-08-13  9:03           ` AdaMagica
2018-08-13  9:07             ` Simon Wright
2018-08-13 15:54               ` Simon Wright
2018-08-13 16:55                 ` Simon Wright
2018-08-14  2:37                 ` AdaMagica
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox