comp.lang.ada
 help / color / mirror / Atom feed
From: Victor Porton <porton@narod.ru>
Subject: Subtypes and type invariants in Ada2012
Date: Mon, 21 Aug 2017 18:38:59 +0300
Date: 2017-08-21T18:38:59+03:00	[thread overview]
Message-ID: <oneuqr$5l9$1@gioia.aioe.org> (raw)

I thought that type invariants are designed for subtypes. I mistook!

--
package X is

  type T is tagged private;

  function F(P: T) return Integer;

  subtype S is T with Type_Invariant => F(T) > 10;

private

  type T is tagged
    record
      X: Integer;
    end record;

end;
--

This does not verify:

$ gnatgcc -c -gnat2012 x.ads
x.ads:7:23: aspect "Type_Invariant" only allowed for private type or 
corresponding full view

So, my question: Is it possible to restrict a subtype with something like a 
type invariant?

I want a subtype restricted by an arbitrary condition. Is it possible?

-- 
Victor Porton - http://portonvictor.org

             reply	other threads:[~2017-08-21 15:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-21 15:38 Victor Porton [this message]
2017-08-21 16:10 ` Subtypes and type invariants in Ada2012 J-P. Rosen
2017-08-21 16:18 ` Dmitry A. Kazakov
2017-08-21 16:29   ` Victor Porton
2017-08-21 16:52     ` Dmitry A. Kazakov
2017-08-21 17:41       ` Victor Porton
2017-08-21 19:55         ` 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