[mcs] Initial by ref returns and variables support
[mono.git] / mcs / mcs / generic.cs
index 2748df0b4f4a7c38fdde879f8a9cda6ef00b6ef1..625cd0c773f0588fefcd0b3055c1ddbc20d0e44a 100644 (file)
@@ -428,13 +428,13 @@ namespace Mono.CSharp {
                public TypeParameter (TypeParameterSpec spec, TypeSpec parentSpec, MemberName name, Attributes attrs)
                        : base (null, name, attrs)
                {
-                       this.spec = new TypeParameterSpec (parentSpec, spec.DeclaredPosition, spec.MemberDefinition, spec.SpecialConstraint, spec.Variance, null) {
+                       this.spec = new TypeParameterSpec (parentSpec, spec.DeclaredPosition, this, spec.SpecialConstraint, spec.Variance, null) {
                                BaseType = spec.BaseType,
                                InterfacesDefined = spec.InterfacesDefined,
                                TypeArguments = spec.TypeArguments
                        };
                }
-               
+
                #region Properties
 
                public override AttributeTargets AttributeTargets {
@@ -1543,6 +1543,9 @@ namespace Mono.CSharp {
                                        if (ec is PointerContainer)
                                                return PointerContainer.MakeType (context.Module, et);
 
+                                       if (ec is ReferenceContainer)
+                                               return ReferenceContainer.MakeType (context.Module, et);
+                                       
                                        throw new NotImplementedException ();
                                }
 
@@ -1772,7 +1775,10 @@ namespace Mono.CSharp {
                        foreach (var arg in targs) {
                                if (arg.HasDynamicElement || arg.BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
                                        state |= StateFlags.HasDynamicElement;
-                                       break;
+                               }
+
+                               if (arg.HasNamedTupleElement) {
+                                       state |= StateFlags.HasNamedTupleElement;
                                }
                        }
 
@@ -1852,6 +1858,12 @@ namespace Mono.CSharp {
                        }
                }
 
+               public override bool IsTupleType {
+                       get {
+                               return (open_type.state & StateFlags.Tuple) != 0;
+                       }
+               }
+
                //
                // Types used to inflate the generic  type
                //
@@ -2162,6 +2174,10 @@ namespace Mono.CSharp {
                                return this;
 
                        var mutated = (InflatedTypeSpec) MemberwiseClone ();
+#if DEBUG
+                       mutated.ID += 1000000;
+#endif
+
                        if (decl != DeclaringType) {
                                // Gets back MethodInfo in case of metaInfo was inflated
                                //mutated.info = MemberCache.GetMember<TypeSpec> (DeclaringType.GetDefinition (), this).info;
@@ -3087,7 +3103,11 @@ namespace Mono.CSharp {
                        // Some types cannot be used as type arguments
                        //
                        if ((bound.Type.Kind == MemberKind.Void && !voidAllowed) || bound.Type.IsPointer || bound.Type.IsSpecialRuntimeType ||
-                               bound.Type == InternalType.MethodGroup || bound.Type == InternalType.AnonymousMethod || bound.Type == InternalType.VarOutType)
+                           bound.Type == InternalType.MethodGroup || bound.Type == InternalType.AnonymousMethod || bound.Type == InternalType.VarOutType ||
+                           bound.Type == InternalType.ThrowExpr)
+                               return;
+
+                       if (bound.Type.IsTupleType && TupleLiteral.ContainsNoTypeElement (bound.Type))
                                return;
 
                        var a = bounds [index];
@@ -3125,7 +3145,7 @@ namespace Mono.CSharp {
                //
                public int ExactInference (TypeSpec u, TypeSpec v)
                {
-                       // If Vs an array type
+                       // If V is an array type
                        if (v.IsArray) {
                                if (!u.IsArray)
                                        return 0;
@@ -3161,7 +3181,7 @@ namespace Mono.CSharp {
 
                                        if (u.TypeArguments.Length != v.TypeArguments.Length)
                                                return 0;
-                                               
+
                                        int score = 0;
                                        for (int i = 0; i < ga_v.Length; ++i)
                                                score += ExactInference (ga_u [i], ga_v [i]);