2007-01-25 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / namespace.cs
index 2449b5a02ac1db4af353c344f4a4b695c4f96a85..af9c93b0d6b3744526fb375606039b4e942eecf1 100644 (file)
@@ -224,11 +224,17 @@ namespace Mono.CSharp {
                                                found_type = t;
                                                continue;
                                        }
-                                       
-                                       Report.SymbolRelatedToPreviousError (t);
+
                                        Report.SymbolRelatedToPreviousError (found_type);
-                                       Report.Warning (436, 2, loc, "Ignoring imported type `{0}' since the current assembly already has a declaration with the same name",
-                                               TypeManager.CSharpName (t));
+                                       if (loc.IsNull) {
+                                               DeclSpace ds = TypeManager.LookupDeclSpace (t);
+                                               Report.Warning (1685, 1, ds.Location, "The type `{0}' conflicts with the predefined type `{1}' and will be ignored",
+                                                       ds.GetSignatureForError (), TypeManager.CSharpName (found_type));
+                                               return found_type;
+                                       }
+                                       Report.SymbolRelatedToPreviousError (t);
+                                       Report.Warning (436, 2, loc, "The type `{0}' conflicts with the imported type `{1}'. Ignoring the imported type definition",
+                                               TypeManager.CSharpName (t), TypeManager.CSharpName (found_type));
                                        return t;
                                }
                        }
@@ -263,7 +269,7 @@ namespace Mono.CSharp {
                {
                        // Expression members.
                        this.eclass = ExprClass.Namespace;
-                       this.Type = null;
+                       this.Type = typeof (Namespace);
                        this.loc = Location.Null;
 
                        this.parent = parent;
@@ -306,7 +312,7 @@ namespace Mono.CSharp {
 
                public virtual void Error_NamespaceDoesNotExist (DeclSpace ds, Location loc, string name)
                {
-                       if (name.IndexOf ("`") > 0) {
+                       if (name.IndexOf ('`') > 0) {
                                FullNamedExpression retval = Lookup (ds, SimpleName.RemoveGenericArity (name), loc);
                                if (retval != null) {
                                        Error_TypeArgumentsCannotBeUsed (retval.Type, loc, "type");
@@ -398,7 +404,9 @@ namespace Mono.CSharp {
                        }
                        string lookup = t != null ? t.FullName : (fullname.Length == 0 ? name : fullname + "." + name);
                        Type rt = root.LookupTypeReflection (lookup, loc);
-                       if (t == null)
+
+                       // HACK: loc.IsNull when the type is core type
+                       if (t == null || (rt != null && loc.IsNull))
                                t = rt;
 
                        TypeExpr te = t == null ? null : new TypeExpression (t, Location.Null);
@@ -527,7 +535,7 @@ namespace Mono.CSharp {
                                resolved = fne as Namespace;
                                if (resolved == null) {
                                        Report.Error (138, Location,
-                                               "`{0} is a type not a namespace. A using namespace directive can only be applied to namespaces", Name.ToString ());
+                                               "`{0}' is a type not a namespace. A using namespace directive can only be applied to namespaces", Name.ToString ());
                                }
                                return resolved;
                        }