+2010-06-01 Marek Safar <marek.safar@gmail.com>
+
+ A fix for bug #610139
+ * generic.cs, convert.cs: Recursively check effective base interface
+
2010-06-01 Marek Safar <marek.safar@gmail.com>
* statement.cs: Handle nullable types and type parameters in using
return new BoxedCast (expr, target_type);
}
- var effective_ifaces = expr_type.Interfaces;
- if (effective_ifaces != null) {
- foreach (var t in effective_ifaces) {
- if (t == target_type || t.ImplementsInterface (target_type)) {
- if (expr_type.IsReferenceType)
- return new ClassCast (expr, target_type);
-
- return new BoxedCast (expr, target_type);
- }
- }
+ if (target_type.IsInterface && expr_type.IsConvertibleToInterface (target_type)) {
+ if (expr_type.IsReferenceType)
+ return new ClassCast (expr, target_type);
+
+ return new BoxedCast (expr, target_type);
}
return null;
}
}
+ public bool IsConvertibleToInterface (TypeSpec iface)
+ {
+ if (Interfaces != null) {
+ foreach (var t in Interfaces) {
+ if (t == iface)
+ return true;
+ }
+ }
+
+ if (TypeArguments != null) {
+ foreach (var t in TypeArguments) {
+ if (((TypeParameterSpec) t).IsConvertibleToInterface (iface))
+ return true;
+ }
+ }
+
+ return false;
+ }
+
public override TypeSpec Mutate (TypeParameterMutator mutator)
{
return mutator.Mutate (this);