with Ada.Text_IO;
procedure Main is
   package P is
      type T is range -100 .. 100;
      function "+" (X : T) return T;
   end P;
   use P;
   package body P is
      function "+" (X : T) return T is (1);
   end P;
   -- (QT's "+" is declared by a renaming, which overrides the one QT inherited from T: a type
   -- derived from QT outside Q inherits the renaming's, by that name)
   package Q is
      type QT is new T;
      X : QT := +0;
      function G (X : QT) return QT;
      function "+" (Y : QT) return QT renames G;
   end Q;
   use Q;
   package body Q is
      function G (X : QT) return QT is (2);
   end Q;
   package R is
      Y : QT := +0;
      type RT is new QT;
      Z : RT := +0;
   end R;
begin
   Ada.Text_IO.Put_Line (QT'Image (Q.X) & QT'Image (R.Y) & R.RT'Image (R.Z));
end Main;
