Merge pull request #807 from akoeplinger/fix-fonttest
[mono.git] / mcs / mcs / typemanager.cs
index cefb322eeb540cbdc3d483c22ebd8ccc1a0b32b6..870b7be2a754773b25c721b29e0fb28b38d4315c 100644 (file)
@@ -186,7 +186,9 @@ namespace Mono.CSharp
                public readonly PredefinedType IsVolatile;
                public readonly PredefinedType IEnumeratorGeneric;
                public readonly PredefinedType IListGeneric;
+               public readonly PredefinedType IReadOnlyListGeneric;
                public readonly PredefinedType ICollectionGeneric;
+               public readonly PredefinedType IReadOnlyCollectionGeneric;
                public readonly PredefinedType IEnumerableGeneric;
                public readonly PredefinedType Nullable;
                public readonly PredefinedType Activator;
@@ -246,7 +248,9 @@ namespace Mono.CSharp
                        IsVolatile = new PredefinedType (module, MemberKind.Class, "System.Runtime.CompilerServices", "IsVolatile");
                        IEnumeratorGeneric = new PredefinedType (module, MemberKind.Interface, "System.Collections.Generic", "IEnumerator", 1);
                        IListGeneric = new PredefinedType (module, MemberKind.Interface, "System.Collections.Generic", "IList", 1);
+                       IReadOnlyListGeneric = new PredefinedType (module, MemberKind.Interface, "System.Collections.Generic", "IReadOnlyList", 1);
                        ICollectionGeneric = new PredefinedType (module, MemberKind.Interface, "System.Collections.Generic", "ICollection", 1);
+                       IReadOnlyCollectionGeneric = new PredefinedType (module, MemberKind.Interface, "System.Collections.Generic", "IReadOnlyCollection", 1);
                        IEnumerableGeneric = new PredefinedType (module, MemberKind.Interface, "System.Collections.Generic", "IEnumerable", 1);
                        Nullable = new PredefinedType (module, MemberKind.Struct, "System", "Nullable", 1);
                        Activator = new PredefinedType (module, MemberKind.Class, "System", "Activator");
@@ -294,13 +298,19 @@ namespace Mono.CSharp
                                ArgIterator.TypeSpec.IsSpecialRuntimeType = true;
 
                        if (IEnumerableGeneric.Define ())
-                               IEnumerableGeneric.TypeSpec.IsGenericIterateInterface = true;
+                               IEnumerableGeneric.TypeSpec.IsArrayGenericInterface = true;
 
                        if (IListGeneric.Define ())
-                               IListGeneric.TypeSpec.IsGenericIterateInterface = true;
+                               IListGeneric.TypeSpec.IsArrayGenericInterface = true;
+
+                       if (IReadOnlyListGeneric.Define ())
+                               IReadOnlyListGeneric.TypeSpec.IsArrayGenericInterface = true;
 
                        if (ICollectionGeneric.Define ())
-                               ICollectionGeneric.TypeSpec.IsGenericIterateInterface = true;
+                               ICollectionGeneric.TypeSpec.IsArrayGenericInterface = true;
+
+                       if (IReadOnlyCollectionGeneric.Define ())
+                               IReadOnlyCollectionGeneric.TypeSpec.IsArrayGenericInterface = true;
 
                        if (Nullable.Define ())
                                Nullable.TypeSpec.IsNullableType = true;
@@ -691,6 +701,7 @@ namespace Mono.CSharp
                readonly MemberKind kind;
                protected readonly ModuleContainer module;
                protected TypeSpec type;
+               bool defined;
 
                public PredefinedType (ModuleContainer module, MemberKind kind, string ns, string name, int arity)
                        : this (module, kind, ns, name)
@@ -753,7 +764,11 @@ namespace Mono.CSharp
                        if (type != null)
                                return true;
 
-                       type = Resolve (module, kind, ns, name, arity, false, false);
+                       if (!defined) {
+                               defined = true;
+                               type = Resolve (module, kind, ns, name, arity, false, false);
+                       }
+
                        return type != null;
                }
 
@@ -771,12 +786,13 @@ namespace Mono.CSharp
                        // fake namespaces when type is optional and does not exist (e.g. System.Linq).
                        //
                        Namespace type_ns = module.GlobalRootNamespace.GetNamespace (ns, required);
+
                        IList<TypeSpec> found = null;
                        if (type_ns != null)
                                found = type_ns.GetAllTypes (name);
 
                        if (found == null) {
-                               if (reportErrors )
+                               if (reportErrors)
                                        module.Compiler.Report.Error (518, "The predefined type `{0}.{1}' is not defined or imported", ns, name);
 
                                return null;
@@ -829,15 +845,22 @@ namespace Mono.CSharp
                        }
 
                        if (best_match == null && reportErrors) {
-                               Location loc;
-                               if (found[0].MemberDefinition is MemberCore) {
-                                       loc = ((MemberCore) found[0].MemberDefinition).Location;
+                               var found_member = found[0];
+
+                               if (found_member.Kind == MemberKind.MissingType) {
+                                       // CSC: should be different error number
+                                       module.Compiler.Report.Error (518, "The predefined type `{0}.{1}' is defined in an assembly that is not referenced.", ns, name);
                                } else {
-                                       loc = Location.Null;
-                                       module.Compiler.Report.SymbolRelatedToPreviousError (found[0]);
-                               }
+                                       Location loc;
+                                       if (found_member.MemberDefinition is MemberCore) {
+                                               loc = ((MemberCore) found_member.MemberDefinition).Location;
+                                       } else {
+                                               loc = Location.Null;
+                                               module.Compiler.Report.SymbolRelatedToPreviousError (found_member);
+                                       }
 
-                               module.Compiler.Report.Error (520, loc, "The predefined type `{0}.{1}' is not declared correctly", ns, name);
+                                       module.Compiler.Report.Error (520, loc, "The predefined type `{0}.{1}' is not declared correctly", ns, name);
+                               }
                        }
 
                        return best_match;