In mcs:
[mono.git] / mcs / gmcs / namespace.cs
index c547f64d598a33d56c594058fbda0dfd70f2685e..be3ccbb59c03bd3e0274ff2b98e361d7fd519a60 100644 (file)
@@ -3,6 +3,7 @@
 //
 // Author:
 //   Miguel de Icaza (miguel@ximian.com)
+//   Marek Safar (marek.safar@seznam.cz)
 //
 // (C) 2001 Ximian, Inc.
 //
@@ -86,7 +87,7 @@ namespace Mono.CSharp {
 
                protected void EnsureNamespace (string dotted_name)
                {
-                       if (dotted_name != null && dotted_name != "" && ! IsNamespace (dotted_name))
+                       if (dotted_name != null && dotted_name.Length != 0 && ! IsNamespace (dotted_name))
                                GetNamespace (dotted_name, true);
                }
 
@@ -187,6 +188,12 @@ namespace Mono.CSharp {
                                EnsureNamespace (t.Namespace);
                }
 
+               public override void Error_NamespaceDoesNotExist(Location loc, string name)
+               {
+                       Report.Error (400, loc, "The type or namespace name `{0}' could not be found in the global namespace (are you missing an assembly reference?)",
+                               name);
+               }
+
                public override Type LookupTypeReflection (string name, Location loc)
                {
                        Type found_type = null;
@@ -281,9 +288,8 @@ namespace Mono.CSharp {
                                throw new InternalErrorException ("Namespace has a null fullname");
 
                        if (parent != null && parent.MemberName != MemberName.Null)
-                               MemberName = new MemberName (
-                                       parent.MemberName, name, parent.MemberName.Location);
-                       else if (name == "")
+                               MemberName = new MemberName (parent.MemberName, name, parent.MemberName.Location);
+                       else if (name.Length == 0)
                                MemberName = MemberName.Null;
                        else
                                MemberName = new MemberName (name, Location.Null);
@@ -299,6 +305,12 @@ namespace Mono.CSharp {
                        return this;
                }
 
+               public virtual void Error_NamespaceDoesNotExist (Location loc, string name)
+               {
+                       Report.Error (234, loc, "The type or namespace name `{0}' does not exist in the namespace `{1}'. Are you missing an assembly reference?",
+                               name, FullName);
+               }
+
                public override void Emit (EmitContext ec)
                {
                        throw new InternalErrorException ("Expression tree referenced namespace " + fullname + " during Emit ()");
@@ -357,7 +369,7 @@ namespace Mono.CSharp {
                                        t = tdecl.TypeBuilder;
                                }
                        }
-                       string lookup = t != null ? t.FullName : (fullname == "" ? name : fullname + "." + name);
+                       string lookup = t != null ? t.FullName : (fullname.Length == 0 ? name : fullname + "." + name);
                        Type rt = root.LookupTypeReflection (lookup, loc);
                        if (t == null)
                                t = rt;
@@ -523,7 +535,18 @@ namespace Mono.CSharp {
                                root.NamespaceEntry = null;
 
                                if (resolved == null)
-                                       Error_NamespaceNotFound (Location, Alias.ToString ());
+                                       return null;
+
+                               if (resolved.Type != null) {
+                                       TypeAttributes attr = resolved.Type.Attributes & TypeAttributes.VisibilityMask;
+                                       if (attr == TypeAttributes.NestedPrivate || attr == TypeAttributes.NestedFamily ||
+                                               ((attr == TypeAttributes.NestedFamORAssem || attr == TypeAttributes.NestedAssembly) && 
+                                               TypeManager.LookupDeclSpace (resolved.Type) == null)) {
+                                               Expression.ErrorIsInaccesible (Alias.Location, Alias.ToString ());
+                                               return null;
+                                       }
+                               }
+
                                return resolved;
                        }
                }
@@ -546,7 +569,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               public NamespaceEntry (NamespaceEntry parent, SourceFile file, string name, Location loc)
+               public NamespaceEntry (NamespaceEntry parent, SourceFile file, string name)
                {
                        this.parent = parent;
                        this.file = file;