comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@world.std.com>
Subject: Re: Compiler complaint legal?
Date: Wed, 20 Jun 2001 21:33:00 GMT
Date: 2001-06-20T21:33:00+00:00	[thread overview]
Message-ID: <wcc4rtaltv7.fsf@world.std.com> (raw)
In-Reply-To: mailman.993057563.10765.comp.lang.ada@ada.eu.org

"M. A. Alves" <maa@liacc.up.pt> writes:

> Package O defines type O.  GNAT does not recognize the type here:
> 
> with O; use O;
> procedure O_Test is
>   Object: O; -- HERE

> Academic question: is this a legal complaint from a (aledgedly) validated
> compiler?

Yes.

Package O hides type O.

> (GNAT says "subtype mark required in this context" which I find confusing
> because one does not immediately realise that what he is missing is a
> "subtype indication" but this is another story I think.)

The compiler first looks for all the O's that are direcly visible.
There's only one -- the package (the type is hidden).
Then it considers whether this thing is legal in this context
-- it isn't, because the thing after the colon should be the name of a
subtype, not the name of a package.  That's why you get the "confusing"
error message.

The visibility rules are spelled out in excruciating detail in chapter 8
of the RM.  The particular case here is: use_clauses are considered
last.  If there's an O visible in some outer scope, it will hide any O
in a 'use'd package (assuming they're not overloadable, as is the case
here).  When you say "with O;" that makes it visible in an outer scope
(namely, the scope of Standard).

If you choose to give your packages and types the same name (which I
don't think is a very good idea), then you will not be able to refer to
the type by its simple name -- you'll have to say O.O.

My style (when I'm using use clauses) is to call the package by the
plural of the type name: package Lists contains type List, or package
Symbol_Tables contains type Symbol_Table.

Another style I've seen is to *always* call the type by a particular
name, (say, T) and always use dot-notation to refer to it: Lists.T,
Symbol_Tables.T.  Here, the name T doesn't give any useful information,
other than the fact that it's a type (or it's the "main" type exported
by that package).  The useful information is embodied in the package
name.  I've also seen "Object" used in place of "T".  I don't really
like that style...

- Bob



  parent reply	other threads:[~2001-06-20 21:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-20 18:17 Compiler complaint legal? M. A. Alves
2001-06-20 17:51 ` Ted Dennison
2001-06-20 18:02   ` Jean-Pierre Rosen
2001-06-20 21:33 ` Robert A Duff [this message]
2001-06-21 23:40 ` Jeff Creem
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox