[#7637][Web]: Support empty write streams.
[mono.git] / mcs / mcs / generic.cs
index 594bbe943a416dfc56f54159dd8d7b318c2f9512..57c7ac96cd7bcb0d5395af27125bb06e19ce729c 100644 (file)
@@ -416,6 +416,12 @@ namespace Mono.CSharp {
                        }
                }
 
+               bool ITypeDefinition.IsPartial {
+                       get {
+                               return false;
+                       }
+               }
+
                public bool IsMethodTypeParameter {
                        get {
                                return spec.IsMethodOwned;
@@ -493,7 +499,7 @@ namespace Mono.CSharp {
 
                        // Copy constraint from resolved part to partial container
                        spec.SpecialConstraint = tp.spec.SpecialConstraint;
-                       spec.InterfacesDefined = tp.spec.InterfacesDefined;
+                       spec.Interfaces = tp.spec.Interfaces;
                        spec.TypeArguments = tp.spec.TypeArguments;
                        spec.BaseType = tp.spec.BaseType;
                        
@@ -725,6 +731,12 @@ namespace Mono.CSharp {
                        }
                }
 
+               public bool HasAnyTypeConstraint {
+                       get {
+                               return (spec & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0 || ifaces != null || targs != null || HasTypeConstraint;
+                       }
+               }
+
                public bool HasTypeConstraint {
                        get {
                                var bt = BaseType.BuiltinType;
@@ -1214,6 +1226,30 @@ namespace Mono.CSharp {
                        return false;
                }
 
+               public static bool HasAnyTypeParameterTypeConstrained (IGenericMethodDefinition md)
+               {
+                       var tps = md.TypeParameters;
+                       for (int i = 0; i < md.TypeParametersCount; ++i) {
+                               if (tps[i].HasAnyTypeConstraint) {
+                                       return true;
+                               }
+                       }
+
+                       return false;
+               }
+
+               public static bool HasAnyTypeParameterConstrained (IGenericMethodDefinition md)
+               {
+                       var tps = md.TypeParameters;
+                       for (int i = 0; i < md.TypeParametersCount; ++i) {
+                               if (tps[i].IsConstrained) {
+                                       return true;
+                               }
+                       }
+
+                       return false;
+               }
+
                public override TypeSpec Mutate (TypeParameterMutator mutator)
                {
                        return mutator.Mutate (this);
@@ -1476,7 +1512,9 @@ namespace Mono.CSharp {
                        if (targs == null)
                                throw new ArgumentNullException ("targs");
 
-//                     this.state = openType.state;
+                       this.state &= ~SharedStateFlags;
+                       this.state |= (openType.state & SharedStateFlags);
+
                        this.context = context;
                        this.open_type = openType;
                        this.targs = targs;
@@ -2136,10 +2174,6 @@ namespace Mono.CSharp {
                        this.args = args;
                }
 
-               public TypeArguments TypeArguments {
-                       get { return args; }
-               }
-
                public override string GetSignatureForError ()
                {
                        return TypeManager.CSharpName (type);
@@ -2210,29 +2244,14 @@ namespace Mono.CSharp {
        struct ConstraintChecker
        {
                IMemberContext mc;
-               bool ignore_inferred_dynamic;
                bool recursive_checks;
 
                public ConstraintChecker (IMemberContext ctx)
                {
                        this.mc = ctx;
-                       ignore_inferred_dynamic = false;
                        recursive_checks = false;
                }
 
-               #region Properties
-
-               public bool IgnoreInferredDynamic {
-                       get {
-                               return ignore_inferred_dynamic;
-                       }
-                       set {
-                               ignore_inferred_dynamic = value;
-                       }
-               }
-
-               #endregion
-
                //
                // Checks the constraints of open generic type against type
                // arguments. This version is used for types which could not be
@@ -2277,14 +2296,11 @@ namespace Mono.CSharp {
 
                //
                // Checks all type arguments againts type parameters constraints
-               // NOTE: It can run in probing mode when `mc' is null
+               // NOTE: It can run in probing mode when `this.mc' is null
                //
                public bool CheckAll (MemberSpec context, TypeSpec[] targs, TypeParameterSpec[] tparams, Location loc)
                {
                        for (int i = 0; i < tparams.Length; i++) {
-                               if (ignore_inferred_dynamic && targs[i].BuiltinType == BuiltinTypeSpec.Type.Dynamic)
-                                       continue;
-
                                var targ = targs[i];
                                if (!CheckConstraint (context, targ, tparams [i], loc))
                                        return false;
@@ -2330,15 +2346,6 @@ namespace Mono.CSharp {
                        // Check the class constraint
                        //
                        if (tparam.HasTypeConstraint) {
-                               var dep = tparam.BaseType.GetMissingDependencies ();
-                               if (dep != null) {
-                                       if (mc == null)
-                                               return false;
-
-                                       ImportedTypeDefinition.Error_MissingDependency (mc, dep, loc);
-                                       ok = false;
-                               }
-
                                if (!CheckConversion (mc, context, atype, tparam, tparam.BaseType, loc)) {
                                        if (mc == null)
                                                return false;
@@ -2352,19 +2359,6 @@ namespace Mono.CSharp {
                        //
                        if (tparam.Interfaces != null) {
                                foreach (TypeSpec iface in tparam.Interfaces) {
-                                       var dep = iface.GetMissingDependencies ();
-                                       if (dep != null) {
-                                               if (mc == null)
-                                                       return false;
-
-                                               ImportedTypeDefinition.Error_MissingDependency (mc, dep, loc);
-                                               ok = false;
-
-                                               // return immediately to avoid duplicate errors because we are scanning
-                                               // expanded interface list
-                                               return false;
-                                       }
-
                                        if (!CheckConversion (mc, context, atype, tparam, iface, loc)) {
                                                if (mc == null)
                                                        return false;
@@ -2454,14 +2448,6 @@ namespace Mono.CSharp {
                                        return true;
                        }
 
-                       //
-                       // When partial/full type inference finds a dynamic type argument delay
-                       // the constraint check to runtime, it can succeed for real underlying
-                       // dynamic type
-                       //
-                       if (ignore_inferred_dynamic && HasDynamicTypeArgument (ttype.TypeArguments))
-                               return true;
-
                        if (mc != null) {
                                mc.Module.Compiler.Report.SymbolRelatedToPreviousError (tparam);
                                if (atype.IsGenericParameter) {
@@ -2494,7 +2480,7 @@ namespace Mono.CSharp {
                        return false;
                }
 
-               bool HasDefaultConstructor (TypeSpec atype)
+               static bool HasDefaultConstructor (TypeSpec atype)
                {
                        var tp = atype as TypeParameterSpec;
                        if (tp != null) {
@@ -2720,7 +2706,7 @@ namespace Mono.CSharp {
                        Upper   = 2
                }
 
-               protected class BoundInfo : IEquatable<BoundInfo>
+               struct BoundInfo : IEquatable<BoundInfo>
                {
                        public readonly TypeSpec Type;
                        public readonly BoundKind Kind;
@@ -2736,14 +2722,14 @@ namespace Mono.CSharp {
                                return Type.GetHashCode ();
                        }
 
-                       public virtual Expression GetTypeExpression ()
+                       public Expression GetTypeExpression ()
                        {
                                return new TypeExpression (Type, Location.Null);
                        }
 
                        #region IEquatable<BoundInfo> Members
 
-                       public virtual bool Equals (BoundInfo other)
+                       public bool Equals (BoundInfo other)
                        {
                                return Type == other.Type && Kind == other.Kind;
                        }
@@ -2799,7 +2785,7 @@ namespace Mono.CSharp {
                        AddToBounds (new BoundInfo (type, BoundKind.Lower), 0);
                }
 
-               protected void AddToBounds (BoundInfo bound, int index)
+               void AddToBounds (BoundInfo bound, int index)
                {
                        //
                        // Some types cannot be used as type arguments
@@ -2870,7 +2856,7 @@ namespace Mono.CSharp {
                                for (int i = 0; i < ga_u.Length; ++i)
                                        score += ExactInference (ga_u [i], ga_v [i]);
 
-                               return score > 0 ? 1 : 0;
+                               return System.Math.Min (1, score);
                        }
 
                        // If V is one of the unfixed type arguments