Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Child packages named Ada illegal?

91 views
Skip to first unread message

Marius Amado-Alves

unread,
Oct 31, 2012, 12:47:04 PM10/31/12
to
I was getting misleading <<missing "with Ada...">> errors from GNAT (the packages were withen). In a moment of inspiration I renamed package AA.Languages.Ada to AA.Languages.Ada_Languages and all went well.

Just curious: was GNAT misbehaving (unlikely) or is it somehow forbidden to have child packages named Ada?

Thanks.

Shark8

unread,
Oct 31, 2012, 1:02:44 PM10/31/12
to
It's probably an issue of visibility. Consider:

with Ada.Calendar.Time;
Procedure Test is
package Ada is
end Ada;

Now : Constant Ada.Calendar.Time:= Ada.Calendar.Clock;
Begin
null;
End Test;

In this case the Now declaration is prevented from being valid because the type, Time, resides in the package Calendar which is a child of Ada... but Ada at that point refers to Test.Ada which has no Calendar child package.

That te following compiles indicates Ada is not reserved:
Procedure Test is
Now : Constant Ada.Calendar.Time:= Ada.Calendar.Clock;
Begin
declare
package Ada is
end Ada;

begin
null;
end;
End Test;

Adam Beneschan

unread,
Oct 31, 2012, 1:20:31 PM10/31/12
to
On Wednesday, October 31, 2012 9:47:04 AM UTC-7, Marius Amado-Alves wrote:
> I was getting misleading <<missing "with Ada...">> errors from GNAT (the packages were withen). In a moment of inspiration I renamed package AA.Languages.Ada to AA.Languages.Ada_Languages and all went well.
>
> Just curious: was GNAT misbehaving (unlikely) or is it somehow forbidden to have child packages named Ada?
>

Without seeing your exact code, it's hard to say for sure, but Shark8 is probably right that it's a visibility issue. If you're inside AA.Languages.Ada, and you refer to the identifier Ada without any other qualification, then that identifier would refer to your child package, not the top level Ada package. (Standard.Ada would still get you the top-level package.) The error messages are confusing, though. I can understand it, because 99.9999% of the time when a user uses one of the language-defined package names and it isn't defined, it's because they forgot to WITH it; the GNAT people apparently didn't think of this possibility, which is understandable.

-- Adam

Marius Amado-Alves

unread,
Oct 31, 2012, 1:59:26 PM10/31/12
to
Thanks. The package is as follows (the entire thing is at sourceforge.net/projects/aalibrary/). GNAT shouts <<missing "with Ada.Characters;">> at line "(if Ada...);". The fix is to rename the package AA.Languages.Ada_Language. The Standard.Ada trick doesn't work.

with Ada.Characters.Handling;
...
package body AA.Languages.Ada is
...
function Non_Alphanum_To_Underscore (From : Character) return Character is
(if Ada.Characters.Handling.Is_Alphanumeric (From) then From else '_');
...
end;

Adam Beneschan

unread,
Oct 31, 2012, 2:16:48 PM10/31/12
to
On Wednesday, October 31, 2012 10:59:26 AM UTC-7, Marius Amado-Alves wrote:
> Thanks. The package is as follows (the entire thing is at sourceforge.net/projects/aalibrary/). GNAT shouts <<missing "with Ada.Characters;">> at line "(if Ada...);". The fix is to rename the package AA.Languages.Ada_Language. The Standard.Ada trick doesn't work.

Hmmm ... interesting, it should work. I'm using an earlier version of GNAT that doesn't support Ada 2012 syntax, so I had to rewrite the function to try your example. But it worked fine (inside AA.Languages.Ada) when I referred to Standard.Ada.Characters.Handling.Is_Alphanumeric. So maybe this is a recently introduced bug?

-- Adam

Marius Amado-Alves

unread,
Oct 31, 2012, 2:41:12 PM10/31/12
to
>> ... The Standard.Ada trick doesn't work.
>
> Hmmm ... interesting, it should work.

Sorry, it does work. Sorry.

/*
I had boobed with the packages file names with all the renaming and copying. And I was writing "with Standard.Ada...." GNAT does not allow that. But we can with Ada.Characters and use Standard.Ada.Characters.

I had never wrote Standard.Ada... before. Sometimes I write Standard.Integer and such, but for some reason Standard.Ada looked strange to me.
*/

Shark8

unread,
Oct 31, 2012, 3:39:32 PM10/31/12
to
> package body AA.Languages.Ada is
> ...
> function Non_Alphanum_To_Underscore (From : Character) return Character is
> (if Ada.Characters.Handling.Is_Alphanumeric (From) then From else '_');
> ...
> end;

One option would be to put package renaming inside the AA or Languages package; thus:

with Ada.Characters;
Package AA.Language is
...
package Internal_Characters Renames Ada.Characters;
End AA.Language;

would allow you to refer to Ada.Characters via the Internal_Characters name.

AdaMagica

unread,
Nov 1, 2012, 5:27:32 AM11/1/12
to
On Wednesday, October 31, 2012 7:41:12 PM UTC+1, Marius Amado-Alves wrote:
> I had boobed with the packages file names with all the renaming and copying. And I was writing "with Standard.Ada...." GNAT does not allow that. But we can with Ada.Characters and use Standard.Ada.Characters.

GNAT does allow this, but then Standard is a package that you defined like so:

package Standard is
....
end Standard;

This is of course very bad because it hides the name of the predefined package Standard. Thus, if you haven't defined such a package Standard, GNAT refused a with clause beginning with Standard.

(Visibility rules in context clauses are a bit different from the rest of source code.)
0 new messages