EnsureNamespace (t.Namespace);
}
- public override void Error_NamespaceDoesNotExist(Location loc, string name)
+ public override void Error_NamespaceDoesNotExist(DeclSpace ds, 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);
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;
}
}
{
// Expression members.
this.eclass = ExprClass.Namespace;
- this.Type = null;
+ this.Type = typeof (Namespace);
this.loc = Location.Null;
this.parent = parent;
return this;
}
- public virtual void Error_NamespaceDoesNotExist (Location loc, string name)
+ public virtual void Error_NamespaceDoesNotExist (DeclSpace ds, Location loc, string name)
{
- Type t = LookForAnyGenericType (name);
- if (t != null) {
- Error_InvalidNumberOfTypeArguments(t, loc);
- return;
+ if (name.IndexOf ('`') > 0) {
+ FullNamedExpression retval = Lookup (ds, SimpleName.RemoveGenericArity (name), loc);
+ if (retval != null) {
+ Error_TypeArgumentsCannotBeUsed (retval.Type, loc, "type");
+ return;
+ }
+ } else {
+ Type t = LookForAnyGenericType (name);
+ if (t != null) {
+ Error_InvalidNumberOfTypeArguments (t, loc);
+ return;
+ }
}
Report.Error (234, loc, "The type or namespace name `{0}' does not exist in the namespace `{1}'. Are you missing an assembly reference?",
TypeManager.CSharpName(t), TypeManager.GetNumberOfTypeArguments(t).ToString());
}
+ public static void Error_TypeArgumentsCannotBeUsed(Type t, Location loc, string symbol)
+ {
+ Report.SymbolRelatedToPreviousError(t);
+ Report.Error(308, loc, "The non-generic {0} `{1}' cannot be used with the type argument(s)",
+ symbol, TypeManager.CSharpName(t));
+ }
+
public override void Emit (EmitContext ec)
{
throw new InternalErrorException ("Expression tree referenced namespace " + fullname + " during Emit ()");
}
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);
///
public Type LookForAnyGenericType (string typeName)
{
- typeName = SimpleName.RemoveGenericArity(typeName);
+ if (declspaces == null)
+ return null;
- foreach (string type_item in declspaces.Keys) {
- string[] sep_type = type_item.Split('`');
- if (sep_type.Length < 2)
- continue;
+ typeName = SimpleName.RemoveGenericArity (typeName);
- if (typeName == sep_type [0]) {
- DeclSpace tdecl = (DeclSpace)declspaces [type_item];
- return tdecl.TypeBuilder;
- }
+ foreach (DictionaryEntry de in declspaces) {
+ string type_item = (string) de.Key;
+ int pos = type_item.LastIndexOf ('`');
+ if (pos == typeName.Length && String.Compare (typeName, 0, type_item, 0, pos) == 0)
+ return ((DeclSpace) de.Value).TypeBuilder;
}
return null;
}
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;
}