2009-06-22 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / class.cs
index 390a16b2b7ba8cecb4468a7e76e7376b24394390..1f84bc436316f89c571a9e33ff6a2018871363a5 100644 (file)
@@ -1289,7 +1289,10 @@ namespace Mono.CSharp {
 
                                        GenericTypeExpr ct = iface as GenericTypeExpr;
                                        if (ct != null) {
-                                               if (!ct.CheckConstraints (this) || !ct.VerifyVariantTypeParameters ())
+                                               // TODO: passing `this' is wrong, should be base type iface instead
+                                               TypeManager.CheckTypeVariance (ct.Type, Variance.Covariant, this);
+
+                                               if (!ct.CheckConstraints (this))
                                                        return false;
                                        }
                                }
@@ -2905,6 +2908,9 @@ namespace Mono.CSharp {
        }
 
        public sealed class Struct : ClassOrStruct {
+
+               bool is_unmanaged, has_unmanaged_check_done;
+
                // <summary>
                //   Modifiers allowed in a struct declaration
                // </summary>
@@ -2964,6 +2970,11 @@ namespace Mono.CSharp {
                        if (requires_delayed_unmanagedtype_check)
                                return true;
 
+                       if (has_unmanaged_check_done)
+                               return is_unmanaged;
+
+                       has_unmanaged_check_done = true;
+
                        foreach (FieldBase f in fields) {
                                if ((f.ModFlags & Modifiers.STATIC) != 0)
                                        continue;
@@ -2972,6 +2983,7 @@ namespace Mono.CSharp {
                                // struct S { S* s; }
                                Type mt = f.MemberType;
                                if (mt == null) {
+                                       has_unmanaged_check_done = false;
                                        requires_delayed_unmanagedtype_check = true;
                                        return true;
                                }
@@ -2988,6 +3000,7 @@ namespace Mono.CSharp {
                                return false;
                        }
 
+                       is_unmanaged = true;
                        return true;
                }
 
@@ -3823,11 +3836,14 @@ namespace Mono.CSharp {
 
                        if ((ModFlags & Modifiers.PARTIAL) != 0) {
                                for (int i = 0; i < Parameters.Count; ++i) {
-                                       if (Parameters.FixedParameters[i].ModFlags == Parameter.Modifier.OUT) {
+                                       IParameterData p = Parameters.FixedParameters [i];
+                                       if (p.ModFlags == Parameter.Modifier.OUT) {
                                                Report.Error (752, Location, "`{0}': A partial method parameters cannot use `out' modifier",
                                                        GetSignatureForError ());
-                                               break;
                                        }
+
+                                       if (p.HasDefaultValue && IsPartialImplementation)
+                                               ((Parameter) p).Warning_UselessOptionalParameter ();
                                }
                        }
                }
@@ -4204,7 +4220,7 @@ namespace Mono.CSharp {
                                return true;
 
                        if (Parameters.HasExtensionMethodType) {
-                               if (Parent.IsStaticClass && !Parent.IsGeneric) {
+                               if (Parent.PartialContainer.IsStaticClass && !Parent.IsGeneric) {
                                        if (!Parent.IsTopLevel)
                                                Report.Error (1109, Location, "`{0}': Extension methods cannot be defined in a nested class",
                                                        GetSignatureForError ());
@@ -4323,6 +4339,11 @@ namespace Mono.CSharp {
                {
                        caching_flags |= Flags.PartialDefinitionExists;
                        methodDefinition.MethodBuilder = MethodBuilder;
+
+                       for (int i = 0; i < methodDefinition.Parameters.Count; ++i ) {
+                               Parameters [i].DefaultValue = methodDefinition.Parameters [i].DefaultValue;
+                       }
+
                        if (methodDefinition.attributes == null)
                                return;
 
@@ -5276,11 +5297,8 @@ namespace Mono.CSharp {
                                                      "accessible than field `" + GetSignatureForError () + "'");
                                }
                        }
-#if GMCS_SOURCE
-                       if (MemberType.IsGenericParameter && (MemberType.GenericParameterAttributes & GenericParameterAttributes.Contravariant) != 0) {
-                               Report.Error (-33, Location, "Contravariant type parameters can only be used in input positions");
-                       }
-#endif
+
+                       TypeManager.CheckTypeVariance (MemberType, Variance.Covariant, this);
                }
 
                protected bool IsTypePermitted ()
@@ -5406,7 +5424,7 @@ namespace Mono.CSharp {
                                return true;
                        }
  
-                       if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE)) == 0) {
+                       if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.BACKING_FIELD)) == 0) {
                                Report.SymbolRelatedToPreviousError (conflict_symbol);
                                Report.Warning (108, 2, Location, "`{0}' hides inherited member `{1}'. Use the new keyword if hiding was intended",
                                        GetSignatureForError (), TypeManager.GetFullNameSignature (conflict_symbol));
@@ -5748,7 +5766,8 @@ namespace Mono.CSharp {
                                MemberType == TypeManager.sbyte_type || MemberType == TypeManager.byte_type ||
                                MemberType == TypeManager.short_type || MemberType == TypeManager.ushort_type ||
                                MemberType == TypeManager.int32_type || MemberType == TypeManager.uint32_type ||
-                               MemberType == TypeManager.float_type)
+                               MemberType == TypeManager.float_type ||
+                               MemberType == TypeManager.intptr_type || MemberType == TypeManager.uintptr_type)
                                return true;
 
                        if (TypeManager.IsEnumType (MemberType))
@@ -7058,14 +7077,16 @@ namespace Mono.CSharp {
                                        GetSignatureForError ());
                        }
 
-                       if (!HasBackingField)
+                       if (!HasBackingField) {
+                               SetMemberIsUsed ();
                                return true;
+                       }
 
                        // FIXME: We are unable to detect whether generic event is used because
                        // we are using FieldExpr instead of EventExpr for event access in that
                        // case.  When this issue will be fixed this hack can be removed.
                        if (TypeManager.IsGenericType (MemberType))
-                               SetMemberIsUsed();
+                               SetMemberIsUsed ();
 
                        if (Add.IsInterfaceImplementation)
                                SetMemberIsUsed ();