comp.lang.ada
 help / color / mirror / Atom feed
From: Andrew Shvets <andrew.shvets@gmail.com>
Subject: What am I doing wrong with contracts?  Why are they succeeding when they should be failing?
Date: Sat, 28 Oct 2017 17:31:25 -0700 (PDT)
Date: 2017-10-28T17:31:25-07:00	[thread overview]
Message-ID: <81f4fbf9-fef3-4592-a95e-64889e564df4@googlegroups.com> (raw)

This is the piece of code that I whipped up (Int_Array is an array of integers):

procedure Multiply_By_Two(Arr : in out Int_Array)
  with Pre  => (for all Item in Arr'Range =>
                  Arr(Item) /= 6),
       Post => (for all Item in Arr'Range =>
                  Arr(Item) = Arr'Old(Item) * 2);


And the implementation in the package:

procedure Multiply_By_Two(
  Arr : in out Int_Array) is

begin
  for iter in Arr'Range loop
    Arr(iter) := Arr(iter) * 2;
  end loop;
end Multiply_By_Two;


I simply pass in the array into Multiply_By_Two and then print out the array as needed.  This is what gets me.  The array has elements going from 6 to 45.  The "Pre" aspect that I created should raise an exception that the passed in element does not meet the conditions for the function to execute successfully.  However, that is not the case.  Why?  I was under the impression that this contract will begin raising exceptions when the Pre aspect evaluates to the condition of False.

Am I missing something?  A compiler flag?

Thank you in advance.


             reply	other threads:[~2017-10-29  0:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-29  0:31 Andrew Shvets [this message]
2017-10-29  0:34 ` What am I doing wrong with contracts? Why are they succeeding when they should be failing? Andrew Shvets
2017-10-29  2:42   ` Andrew Shvets
2017-10-29  7:20     ` joakimds
2017-10-29 13:42       ` Andrew Shvets
2017-10-29 19:17         ` Anh Vo
2017-10-29 19:41           ` Andrew Shvets
2017-10-30  0:16 ` Shark8
2017-10-30  1:37   ` Andrew Shvets
replies disabled

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