2004-08-02 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / gmcs / generic.cs
index 2b13e2099ae70163f0b8b90422b9c0cd21725694..a055cb3b940d22198ec873232f44cf9ff5861cb7 100644 (file)
@@ -136,14 +136,6 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public TypeExpr[] InterfaceConstraints {
-                       get {
-                               TypeExpr[] ifaces = new TypeExpr [iface_constraints.Count];
-                               iface_constraints.CopyTo (ifaces, 0);
-                               return ifaces;
-                       }
-               }
-
                public bool ResolveTypes (EmitContext ec)
                {
                        iface_constraint_types = new Type [iface_constraints.Count];
@@ -295,12 +287,10 @@ namespace Mono.CSharp {
                public void Define (GenericTypeParameterBuilder type)
                {
                        this.type = type;
-                       TypeExpr[] ifaces = null;
-                       if (constraints != null) {
-                               ifaces = constraints.InterfaceConstraints;
+                       Type[] ifaces = null;
+                       if (constraints != null)
                                constraints.Define (type);
-                       }
-                       TypeManager.AddTypeParameter (type, this, ifaces);
+                       TypeManager.AddTypeParameter (type, this);
                }
 
                public bool DefineType (EmitContext ec)
@@ -315,6 +305,7 @@ namespace Mono.CSharp {
                                        type.SetBaseTypeConstraint (gc.ClassConstraint);
 
                                type.SetInterfaceConstraints (gc.InterfaceConstraints);
+                               TypeManager.RegisterBuilder (type, gc.InterfaceConstraints);
                        }
 
                        return true;
@@ -609,14 +600,19 @@ namespace Mono.CSharp {
                        if (TypeManager.HasGenericArguments (ctype)) {
                                Type[] types = TypeManager.GetTypeArguments (ctype);
 
-                               TypeArguments args = new TypeArguments (loc);
+                               TypeArguments new_args = new TypeArguments (loc);
 
                                for (int i = 0; i < types.Length; i++) {
-                                       Type t = types [i] == ptype ? expr.Type : types [i];
-                                       args.Add (new TypeExpression (t, loc));
+                                       Type t = types [i];
+
+                                       if (t.IsGenericParameter) {
+                                               int pos = t.GenericParameterPosition;
+                                               t = args.Arguments [pos];
+                                       }
+                                       new_args.Add (new TypeExpression (t, loc));
                                }
 
-                               ctype = new ConstructedType (ctype, args, loc).ResolveType (ec);
+                               ctype = new ConstructedType (ctype, new_args, loc).ResolveType (ec);
                                if (ctype == null)
                                        return false;
                        }
@@ -676,11 +672,7 @@ namespace Mono.CSharp {
                        //
                        // Now, check the interface constraints.
                        //
-                       foreach (TypeExpr iface in TypeManager.GetInterfaces (ptype)) {
-                               Type itype = iface.ResolveType (ec);
-                               if (itype == null)
-                                       return false;
-
+                       foreach (Type itype in TypeManager.GetInterfaces (ptype)) {
                                if (!CheckConstraint (ec, ptype, aexpr, itype)) {
                                        Report.Error (309, loc, "The type `{0}' must be " +
                                                      "convertible to `{1}' in order to " +
@@ -841,12 +833,6 @@ namespace Mono.CSharp {
                        get { return false; }
                }
 
-               public override TypeExpr[] GetInterfaces ()
-               {
-                       TypeExpr[] ifaces = TypeManager.GetInterfaces (gt);
-                       return ifaces;
-               }
-
                public override bool Equals (object obj)
                {
                        ConstructedType cobj = obj as ConstructedType;