Subtypes are not visible when limited with'd?

Is this normal?

The compiler kept telling me that LR_Axes was not in the package I was referencing, when it was.

So, I changed it to a type and it stopped complaining. WTAF?

This is in the spec, not the body which has a full view of the package.

The source is:

with SDL.Inputs.Joysticks.Events;
limited with SDL.Inputs.Joysticks.Game_Controllers.Events;

package SDL.Inputs.Joysticks.Game_Controllers is
   pragma Preelaborate;

...

   function Axis_Value (Self : in Game_Controller;
                        Axis : in Events.LR_Axes)
                       return Events.LR_Axes_Values;

...
end SDL.Inputs.Joysticks.Game_Controllers;

with Interfaces.C.Strings;
with SDL.Error;
with SDL.RWops;
with SDL.Inputs.Joysticks.Game_Controllers.Events;

package body SDL.Inputs.Joysticks.Game_Controllers is
...
   function Axis_Value (Self : in Game_Controller;
                        Axis : in Events.LR_Axes)
                       return Events.LR_Axes_Values is

      function SDL_Game_Controller_Get_Axis (Controller : in SDL.C_Pointers.Game_Controller_Pointer;
                                             Axis       : in Events.LR_Axes)
                                            return Events.LR_Axes_Values with
        Import        => True,
        Convention    => C,
        External_Name => "SDL_GameControllerGetAxis";
   begin
      return SDL_Game_Controller_Get_Axis (Self.Internal, Axis);
   end Axis_Value;
...
end SDL.Inputs.Joysticks.Game_Controllers;

package SDL.Inputs.Joysticks.Game_Controllers.Events is
   pragma Preelaborate;

   type Axes is (Invalid,
                 Left_X,
                 Left_Y,
                 Right_X,
                 Right_Y,
                 Trigger_Left,
                 Trigger_Right) with
     Convention => C;

   for Axes use (Invalid       => -1,
                 Left_X        =>  0,
                 Left_Y        =>  1,
                 Right_X       =>  2,
                 Right_Y       =>  3,
                 Trigger_Left  =>  4,
                 Trigger_Right =>  5);

   subtype LR_Axes      is Axes range Left_X .. Right_Y;
   subtype Trigger_Axes is Axes range Trigger_Left .. Trigger_Right;

...
end SDL.Inputs.Joysticks.Game_Controllers.Events;

and the build errors:

   [Ada]          sdl-inputs-joysticks-game_controllers-events.adb
sdl-inputs-joysticks-game_controllers.ads:60:41: error: "LR_Axes" not declared in "Events"
sdl-inputs-joysticks-game_controllers.ads:64:41: error: "Trigger_Axes" not declared in "Events"
sdl-inputs-joysticks-game_controllers.adb:65:13: error: not type conformant with declaration at sdl-inputs-joysticks-game_controllers.ads:59
sdl-inputs-joysticks-game_controllers.adb:65:13: error: return type does not match
sdl-inputs-joysticks-game_controllers.ads:60:41: error: "LR_Axes" not declared in "Events"
sdl-inputs-joysticks-game_controllers.ads:64:41: error: "Trigger_Axes" not declared in "Events"

   compilation of sdl-inputs-joysticks-game_controllers-events.adb failed
   compilation of sdl-inputs-joysticks-game_controllers.adb failed

No, package limited view doesn’t include subtypes :person_shrugging:

Well, that’s annoying and short sighted.

Well, guessing, subtype has no incomplete view. They break out of separation interface and implementation. So you need the whole to chip something away. Theoretically one could classify constraints into view and implementation ones. Then subtypes constraining only the view could made visible.

Why do you need limited with? It is a crying wolf from the design point of view.

I need it to compile otherwise you get cyclic errors.

I mean that if you need that you might wish to review the design. Circular dependencies are like gotos, a big no-no.

I’m trying to rearrange the events packages, I’m making them children of the sdl.input.* packages they relate to, apart from window stuff which is a child of that. Then I’ll be cleaning up the entire lot, so it’s likely those dependencies should go away.

Limited with provides a limited view of the package. The limited view of a package is defined in ARM 10.1.1(12.1-3/2) :

12.1/2

For each library package_declaration in the environment, there is an implicit declaration of a limited view of that library package. The limited view of a package contains:

12.2/3

For each package_declaration occurring immediately within the visible part, a declaration of the limited view of that package, with the same defining_program_unit_name.

12.3/3

For each type_declaration occurring immediately within the visible part that is not an incomplete_type_declaration, an incomplete view of the type with no discriminant_part; if the type_declaration is tagged, then the view is a tagged incomplete view.

So limited with only provides visibility to nested packages and type declarations.

Limited with is a hack to work around poor designs. I usually prefer to use a better design.

TBH, Ada doesn’t really provide a good way to encapsulate trees of related types. This would be a good design if there was a way to use the types.

My original tree shows how common items, events in this case should be under one tree, but getting each event type which has been separated out into it’s own package and combined into the one variant record cannot be done at the root SDL.Events package so was nested in an awfully named SDL.Events.Events.Event.