Modifiers.UNSAFE |
Modifiers.PRIVATE;
- public Delegate (NamespaceEntry ns, TypeContainer parent, Expression type,
+ public Delegate (NamespaceEntry ns, DeclSpace parent, Expression type,
int mod_flags, MemberName name, Parameters param_list,
Attributes attrs)
: base (ns, parent, name, attrs)
arg_count = args.Count;
Expression ml = Expression.MemberLookup (
- ec, delegate_type, "Invoke", loc);
+ ec.ContainerType, delegate_type, "Invoke", loc);
MethodGroupExpr me = ml as MethodGroupExpr;
if (me == null) {
/// Verifies whether the delegate in question is compatible with this one in
/// order to determine if instantiation from the same is possible.
/// </summary>
- public static bool VerifyDelegate (EmitContext ec, Type delegate_type, Type probe_type, Location loc)
+ public static bool VerifyDelegate (EmitContext ec, Type delegate_type, Location loc)
{
Expression ml = Expression.MemberLookup (
- ec, delegate_type, "Invoke", loc);
+ ec.ContainerType, delegate_type, "Invoke", loc);
if (!(ml is MethodGroupExpr)) {
Report.Error (-100, loc, "Internal error: could not find Invoke method!");
ParameterData pd = TypeManager.GetParameterData (mb);
Expression probe_ml = Expression.MemberLookup (
- ec, delegate_type, "Invoke", loc);
+ ec.ContainerType, delegate_type, "Invoke", loc);
if (!(probe_ml is MethodGroupExpr)) {
Report.Error (-100, loc, "Internal error: could not find Invoke method!");
protected MethodGroupExpr method_group;
protected Expression delegate_instance_expression;
- public DelegateCreation () {}
+ protected DelegateCreation () {}
public static void Error_NoMatchingMethodForDelegate (EmitContext ec, MethodGroupExpr mg, Type type, Location loc)
{
protected bool ResolveConstructorMethod (EmitContext ec)
{
Expression ml = Expression.MemberLookup (
- ec, type, ".ctor", loc);
+ ec.ContainerType, type, ".ctor", loc);
if (!(ml is MethodGroupExpr)) {
Report.Error (-100, loc, "Internal error: Could not find delegate constructor!");
return null;
}
- protected Expression ResolveMethodGroupExpr (EmitContext ec, MethodGroupExpr mg,
- bool check_only)
+ protected Expression ResolveMethodGroupExpr (EmitContext ec, MethodGroupExpr mg)
{
- foreach (MethodInfo mi in mg.Methods){
- delegate_method = Delegate.VerifyMethod (ec.ContainerType, type, mg, mi, loc);
-
- if (delegate_method != null)
- break;
- }
-
+ delegate_method = ImplicitStandardConversionExists (mg, type);
+
if (delegate_method == null) {
- if (!check_only)
- Error_NoMatchingMethodForDelegate (ec, mg, type, loc);
+ Error_NoMatchingMethodForDelegate (ec, mg, type, loc);
return null;
}
}
static public Expression Create (EmitContext ec, MethodGroupExpr mge,
- Type target_type, bool check_only, Location loc)
+ Type target_type, Location loc)
{
ImplicitDelegateCreation d = new ImplicitDelegateCreation (target_type, loc);
- if (d.ResolveConstructorMethod (ec))
- return d.ResolveMethodGroupExpr (ec, mge, check_only);
- else
+ if (!d.ResolveConstructorMethod (ec))
return null;
+
+ return d.ResolveMethodGroupExpr (ec, mge);
}
}
Argument a = (Argument) Arguments [0];
- if (!a.ResolveMethodGroup (ec, loc))
+ if (!a.ResolveMethodGroup (ec))
return null;
Expression e = a.Expr;
if (e is AnonymousMethod && RootContext.Version != LanguageVersion.ISO_1)
- return ((AnonymousMethod) e).Compatible (ec, type, false);
+ return ((AnonymousMethod) e).Compatible (ec, type);
MethodGroupExpr mg = e as MethodGroupExpr;
if (mg != null)
- return ResolveMethodGroupExpr (ec, mg, false);
-
- Type e_type = e.Type;
+ return ResolveMethodGroupExpr (ec, mg);
- if (!TypeManager.IsDelegateType (e_type)) {
+ if (!TypeManager.IsDelegateType (e.Type)) {
Report.Error (149, loc, "Method name expected");
return null;
}
// This is what MS' compiler reports. We could always choose
// to be more verbose and actually give delegate-level specifics
- if (!Delegate.VerifyDelegate (ec, type, e_type, loc)) {
- Report.Error (29, loc, "Cannot implicitly convert type '" + e_type + "' " +
+ if (!Delegate.VerifyDelegate (ec, type, loc)) {
+ Report.Error (29, loc, "Cannot implicitly convert type '" + e.Type + "' " +
"to type '" + type + "'");
return null;
}
if (!Delegate.VerifyApplicability (ec, del_type, Arguments, loc))
return null;
- Expression lookup = Expression.MemberLookup (ec, del_type, "Invoke", loc);
+ Expression lookup = Expression.MemberLookup (ec.ContainerType, del_type, "Invoke", loc);
if (!(lookup is MethodGroupExpr)) {
Report.Error (-100, loc, "Internal error: could not find Invoke method!");
return null;