2

I started to learn Ada yesterday but I don't really understand the Dynamic_Predicate'aspect. when declaring:

type evenInt is new Integer
 with Dynamic_Predicate => evenInt mod 2 = 0;

Why is it still possible to:

anOddNum : evenInt := 7;

since:

Dynamic_Predicate => evenInt mod 2 = 0 

forbids to declare odd numbers?

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
Markus
  • 93
  • 6

1 Answers1

3

You need to compile with assertions enabled (-gnata)

egilhh
  • 6,464
  • 1
  • 18
  • 19
  • Note that this is specific to GNAT. It looks like you can use `pragma Assertion_Policy` to control this in manner that should be portable to other implementations. – Keith Thompson Nov 10 '14 at 18:40
  • One could say it's a mistake on the part of GNAT for the assertions to be disabled by default given they chose to use assertions as the mechanism for aspects. – Shark8 Nov 23 '14 at 22:18