2009-05-27 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / decl.cs
index d49d0641e855b6cb179a3ac2122e9a3166e701eb..13065b52be7896c3a0bea8bc3fe324ac13cfdadd 100644 (file)
@@ -349,7 +349,7 @@ namespace Mono.CSharp {
                                }
                        } else {
                                if ((ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN | Modifiers.PARTIAL)) == 0) {
-                                       if (RootContext.Version >= LanguageVersion.LINQ) {
+                                       if (RootContext.Version >= LanguageVersion.V_3) {
                                                Property.PropertyMethod pm = this as Property.PropertyMethod;
                                                if (pm is Indexer.GetIndexerMethod || pm is Indexer.SetIndexerMethod)
                                                        pm = null;
@@ -1334,9 +1334,14 @@ namespace Mono.CSharp {
                                        }
                                }
 
+                               var variance = name.Variance;
+                               if (name.Variance != Variance.None && !(this is Delegate || this is Interface)) {
+                                       Report.Error (1960, name.Location, "Variant type parameters can only be used with interfaces and delegates");
+                                       variance = Variance.None;
+                               }
+
                                type_params [i] = new TypeParameter (
-                                       Parent, this, name.Name, constraints, name.OptAttributes, name.Variance,
-                                       Location);
+                                       Parent, this, name.Name, constraints, name.OptAttributes, variance, Location);
 
                                AddToContainer (type_params [i], name.Name);
                        }