Comment.
[mono.git] / mcs / mcs / generic.cs
index 00c6930d17f08497acee0d132163a4328227f2d6..11a913a4f6d0362f46cfce7fe0415e7b3411d4e7 100644 (file)
@@ -948,9 +948,9 @@ namespace Mono.CSharp {
                        var tps = (TypeParameterSpec) MemberwiseClone ();
                        tps.BaseType = inflator.Inflate (BaseType);
                        if (ifaces != null) {
-                               tps.ifaces = new TypeSpec[ifaces.Count];
+                               tps.ifaces = new List<TypeSpec> (ifaces.Count);
                                for (int i = 0; i < ifaces.Count; ++i)
-                                       tps.ifaces[i] = inflator.Inflate (ifaces[i]);
+                                       tps.ifaces.Add (inflator.Inflate (ifaces[i]));
                        }
                        if (targs != null) {
                                tps.targs = new TypeSpec[targs.Length];
@@ -976,6 +976,25 @@ namespace Mono.CSharp {
                        }
                }
 
+               public bool IsConvertibleToInterface (TypeSpec iface)
+               {
+                       if (Interfaces != null) {
+                               foreach (var t in Interfaces) {
+                                       if (t == iface)
+                                               return true;
+                               }
+                       }
+
+                       if (TypeArguments != null) {
+                               foreach (var t in TypeArguments) {
+                                       if (((TypeParameterSpec) t).IsConvertibleToInterface (iface))
+                                               return true;
+                               }
+                       }
+
+                       return false;
+               }
+
                public override TypeSpec Mutate (TypeParameterMutator mutator)
                {
                        return mutator.Mutate (this);
@@ -1083,7 +1102,7 @@ namespace Mono.CSharp {
                                if (tparams [i] == tp)
                                        return targs[i];
 
-                       // CECIL: This can happen when inflating nested types
+                       // This can happen when inflating nested types
                        // without type arguments specified
                        return tp;
                }
@@ -1981,14 +2000,21 @@ namespace Mono.CSharp {
                        for (int i = 0; i < names.Length; i++) {
                                string type_argument_name = names[i].Name;
                                int idx = parameters.GetParameterIndexByName (type_argument_name);
+
                                if (idx >= 0) {
-                                       Block b = m.Block;
+                                       var b = m.Block;
                                        if (b == null)
-                                               b = new Block (null);
+                                               b = new ToplevelBlock (Compiler, Location);
 
-                                       b.Error_AlreadyDeclaredTypeParameter (Report, parameters [i].Location,
+                                       b.Error_AlreadyDeclaredTypeParameter (parameters [i].Location,
                                                type_argument_name, "method parameter");
                                }
+
+                               if (m.Block != null) {
+                                       var ikv = m.Block.GetKnownVariable (type_argument_name);
+                                       if (ikv != null)
+                                               ikv.Block.Error_AlreadyDeclaredTypeParameter (ikv.Location, type_argument_name, "local variable");
+                               }
                                
                                snames[i] = type_argument_name;
                        }