Search code examples
integeradacontractgnat

Why is Dynamic_Predicate not working?


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?


Solution

  • You need to compile with assertions enabled (-gnata)