The Ada Program: cnst.adb

  1 -- cnst.adb:  constants are not inherited by derived types
  2 
  3 procedure Cnst is
  4 
  5    -- package required for subprograms to be derivable, ARM 3.4.11
  6    package Pack is
  7       type T is record null; end record;
  8       procedure P (x: T);
  9       X: constant T := T'(null record);
 10    end Pack;
 11    package body Pack is
 12       procedure P (x: T) is begin null; end P;
 13    end Pack;
 14 
 15    -- a package just for the sake of symmetry
 16    package Quack is
 17       type D is new Pack.T;
 18    end Quack;
 19 
 20    A: Pack.T;
 21    B: Quack.D;
 22 
 23 begin
 24 
 25    -- Derived type "D" in package "Quack" inherits procedure "P".
 26    Pack.P (A);
 27    Quack.P (B);
 28 
 29    -- Subprograms are inherited by derived types, but constants are not.
 30    -- No Quack.X exists:  "B:=Quack.X;" yields "X" not declared in "Quack"
 31    A := Pack.X;
 32 
 33 end Cnst;