dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [DotGNU]Another compiler question (namespace)


From: Rhys Weatherley
Subject: Re: [DotGNU]Another compiler question (namespace)
Date: Tue, 22 Oct 2002 10:37:15 +1000

Gopal V wrote:
> 
> Code:
> 
> using ThisDoesNotExist.Foo;
> public class XYZ
> {
> .....
> }
> 
> Should the compiler complain that it cannot find a ThisDoesNotExist.Foo
> namespace ?.

The problem is that it is extremely difficult/inefficient to
do this check.  There is no list of namespaces in assemblies.
The only way to get the namespaces of an assembly is to scan
every single class and compile a sorted list.

And even that isn't enough: the code may be using a namespace
delcared in a different source file that the compiler hasn't
seen yet.  (e.g. "using System.Reflection" from a "System"
class).

Hence the current behaviour of "believe the programmer and
raise an error when they try to access a non-existent class".

> For example
> 
> using System.IO;
> 
> adds the System.IO as a SUBSCOPE of System into the RBTree via
> FindNamespaceScope() without any further checks or verification.
> (hmm...)
> 
> This introduces a potential bug that
> 
> using System.String;
> 
> will destroy the type System.String and replace it with a namespace
> decl, even though System.String does not exist :-(

You could always try to look up the qualified name as a type,
and then bail out if a type is found.  Or enter it into a
different list or something.

The "using" code is very ancient, and a redesign may be in
order anyway.  I'm not sure if "using X = Y" works at all
in the current design.

Oh, and while you're at it: remove the implicit inclusion
of the "System" namespace.  It's against the spec.

(Of course, my preferred option would be to change the damn
spec so that different syntax is used for declaring namespaces
and types :-) ).

Cheers,

Rhys.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]