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];
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)
type.SetBaseTypeConstraint (gc.ClassConstraint);
type.SetInterfaceConstraints (gc.InterfaceConstraints);
+ TypeManager.RegisterBuilder (type, gc.InterfaceConstraints);
}
return true;
bool ok = true;
atypes = new Type [count];
-
+
for (int i = 0; i < count; i++){
TypeExpr te = ds.ResolveTypeExpr (
(Expression) args [i], false, Location);
}
}
+ protected bool CheckConstraint (EmitContext ec, Type ptype, Expression expr,
+ Type ctype)
+ {
+ if (TypeManager.HasGenericArguments (ctype)) {
+ Type[] types = TypeManager.GetTypeArguments (ctype);
+
+ TypeArguments new_args = new TypeArguments (loc);
+
+ for (int i = 0; i < types.Length; i++) {
+ 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, new_args, loc).ResolveType (ec);
+ if (ctype == null)
+ return false;
+ }
+
+ return Convert.ImplicitStandardConversionExists (expr, ctype);
+ }
+
protected bool CheckConstraints (EmitContext ec, int index)
{
Type atype = atypes [index];
// The class constraint comes next.
//
if ((parent != null) && (parent != TypeManager.object_type)) {
- if (!Convert.ImplicitStandardConversionExists (aexpr, parent)) {
+ if (!CheckConstraint (ec, ptype, aexpr, parent)) {
Report.Error (309, loc, "The type `{0}' must be " +
"convertible to `{1}' in order to " +
"use it as parameter `{2}' in the " +
//
// Now, check the interface constraints.
//
- foreach (TypeExpr iface in TypeManager.GetInterfaces (ptype)) {
- Type itype = iface.ResolveType (ec);
- if (itype == null)
- return false;
-
- if (!Convert.ImplicitStandardConversionExists (aexpr, itype)) {
+ 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 " +
"use it as parameter `{2}' in the " +
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;
public string Basename {
get {
- int pos = name.LastIndexOf ('!');
+ int pos = name.LastIndexOf ('`');
if (pos >= 0)
return name.Substring (0, pos);
else
throw new Exception ();
}
- public override bool Define (TypeContainer parent)
+ public override bool Define ()
{
for (int i = 0; i < TypeParameters.Length; i++)
- if (!TypeParameters [i].Resolve (parent))
+ if (!TypeParameters [i].Resolve (Parent))
return false;
return true;
}
- public bool Define (TypeContainer parent, MethodBuilder mb)
+ public bool Define (MethodBuilder mb)
{
- if (!Define (parent))
+ if (!Define ())
return false;
GenericTypeParameterBuilder[] gen_params;