The Ada Program: derived.adb

  1 -- derived.adb:  type of derived subprograms
  2 
  3 procedure derived is
  4    -- package required for subprograms to be derivable, ARM 3.4.11
  5    package pack is
  6        type T is record null; end record;
  7        procedure p (x: T);
  8        function q (x,y: T) return T;
  9    end pack;
 10    package body pack is
 11        procedure p (x: T) is begin null; end p;
 12        function q (x,y: T) return T is begin return (x); end q;
 13    end pack;
 14 
 15    package Quack is
 16       type D is new Pack.T;
 17    end Quack;
 18 
 19    A: Pack.T;
 20    B: Quack.D;
 21 
 22 begin
 23    Pack.P(A);
 24    Quack.P(B);
 25    B := Quack.Q (B, B);
 26    A := Quack.Q (B, B);      -- ILLEGAL!  No such q derived
 27    B := Quack.Q (A, B);      -- ILLEGAL!  No such q derived
 28 end;