2 // delegate.cs: Delegate Handler
5 // Ravi Pratap (ravi@ximian.com)
6 // Miguel de Icaza (miguel@ximian.com)
8 // Licensed under the terms of the GNU GPL
10 // (C) 2001 Ximian, Inc (http://www.ximian.com)
15 using System.Collections;
16 using System.Reflection;
17 using System.Reflection.Emit;
20 namespace Mono.CSharp {
25 public class Delegate : DeclSpace {
26 public Expression ReturnType;
27 public Parameters Parameters;
29 public ConstructorBuilder ConstructorBuilder;
30 public MethodBuilder InvokeBuilder;
31 public MethodBuilder BeginInvokeBuilder;
32 public MethodBuilder EndInvokeBuilder;
36 static string[] attribute_targets = new string [] { "type", "return" };
38 Expression instance_expr;
39 MethodBase delegate_method;
40 ReturnParameter return_attributes;
42 const int AllowedModifiers =
50 public Delegate (NamespaceEntry ns, DeclSpace parent, Expression type,
51 int mod_flags, MemberName name, Parameters param_list,
53 : base (ns, parent, name, attrs)
56 this.ReturnType = type;
57 ModFlags = Modifiers.Check (AllowedModifiers, mod_flags,
58 IsTopLevel ? Modifiers.INTERNAL :
59 Modifiers.PRIVATE, name.Location);
60 Parameters = param_list;
63 public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
65 if (a.Target == AttributeTargets.ReturnValue) {
66 if (return_attributes == null)
67 return_attributes = new ReturnParameter (InvokeBuilder, Location);
69 return_attributes.ApplyAttributeBuilder (a, cb);
73 base.ApplyAttributeBuilder (a, cb);
76 public override TypeBuilder DefineType ()
78 if (TypeBuilder != null)
81 if (TypeManager.multicast_delegate_type == null && !RootContext.StdLib) {
82 Namespace system = RootNamespace.Global.GetNamespace ("System", true);
83 TypeExpr expr = system.Lookup (this, "MulticastDelegate", Location) as TypeExpr;
84 TypeManager.multicast_delegate_type = expr.Type;
87 if (TypeManager.multicast_delegate_type == null)
88 throw new InternalErrorException ("System.MulticastDelegate unresolved");
91 if (TypeManager.NamespaceClash (Name, Location))
94 ModuleBuilder builder = CodeGen.Module.Builder;
96 TypeBuilder = builder.DefineType (
97 Name, TypeAttr, TypeManager.multicast_delegate_type);
99 TypeBuilder builder = Parent.TypeBuilder;
101 string name = Name.Substring (1 + Name.LastIndexOf ('.'));
102 TypeBuilder = builder.DefineNestedType (
103 name, TypeAttr, TypeManager.multicast_delegate_type);
106 TypeManager.AddUserType (this);
111 public override bool Define ()
113 // FIXME: POSSIBLY make this static, as it is always constant
115 Type [] const_arg_types = new Type [2];
116 const_arg_types [0] = TypeManager.object_type;
117 const_arg_types [1] = TypeManager.intptr_type;
119 const MethodAttributes ctor_mattr = MethodAttributes.RTSpecialName | MethodAttributes.SpecialName |
120 MethodAttributes.HideBySig | MethodAttributes.Public;
122 ConstructorBuilder = TypeBuilder.DefineConstructor (ctor_mattr,
123 CallingConventions.Standard,
126 ConstructorBuilder.DefineParameter (1, ParameterAttributes.None, "object");
127 ConstructorBuilder.DefineParameter (2, ParameterAttributes.None, "method");
129 // HACK because System.Reflection.Emit is lame
131 Parameter [] fixed_pars = new Parameter [2];
132 fixed_pars [0] = new Parameter (TypeManager.object_type, "object",
133 Parameter.Modifier.NONE, null, Location);
134 fixed_pars [1] = new Parameter (TypeManager.intptr_type, "method",
135 Parameter.Modifier.NONE, null, Location);
136 Parameters const_parameters = new Parameters (fixed_pars);
137 const_parameters.Resolve (null);
139 TypeManager.RegisterMethod (ConstructorBuilder, const_parameters);
142 ConstructorBuilder.SetImplementationFlags (MethodImplAttributes.Runtime);
145 // Here the various methods like Invoke, BeginInvoke etc are defined
147 // First, call the `out of band' special method for
148 // defining recursively any types we need:
150 if (!Parameters.Resolve (this))
157 // Check accessibility
158 foreach (Type partype in Parameters.Types){
159 if (!Parent.AsAccessible (partype, ModFlags)) {
160 Report.Error (59, Location,
161 "Inconsistent accessibility: parameter type `" +
162 TypeManager.CSharpName (partype) + "' is less " +
163 "accessible than delegate `" + Name + "'");
168 ReturnType = ReturnType.ResolveAsTypeTerminal (this, false);
169 if (ReturnType == null)
172 ret_type = ReturnType.Type;
174 if (!Parent.AsAccessible (ret_type, ModFlags)) {
175 Report.Error (58, Location,
176 "Inconsistent accessibility: return type `" +
177 TypeManager.CSharpName (ret_type) + "' is less " +
178 "accessible than delegate `" + Name + "'");
182 if (RootContext.StdLib && (ret_type == TypeManager.arg_iterator_type || ret_type == TypeManager.typed_reference_type)) {
183 Method.Error1599 (Location, ret_type);
188 // We don't have to check any others because they are all
189 // guaranteed to be accessible - they are standard types.
192 CallingConventions cc = Parameters.CallingConvention;
194 const MethodAttributes mattr = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Virtual | MethodAttributes.NewSlot;
196 InvokeBuilder = TypeBuilder.DefineMethod ("Invoke",
202 InvokeBuilder.SetImplementationFlags (MethodImplAttributes.Runtime);
204 TypeManager.RegisterMethod (InvokeBuilder, Parameters);
210 Parameters async_parameters = Parameters.MergeGenerated (Parameters,
211 new Parameter (TypeManager.asynccallback_type, "callback", Parameter.Modifier.NONE, null, Location),
212 new Parameter (TypeManager.object_type, "object", Parameter.Modifier.NONE, null, Location));
214 BeginInvokeBuilder = TypeBuilder.DefineMethod ("BeginInvoke",
215 mattr, cc, TypeManager.iasyncresult_type, async_parameters.Types);
217 BeginInvokeBuilder.SetImplementationFlags (MethodImplAttributes.Runtime);
218 async_parameters.ApplyAttributes (BeginInvokeBuilder);
219 TypeManager.RegisterMethod (BeginInvokeBuilder, async_parameters);
222 // EndInvoke is a bit more interesting, all the parameters labeled as
223 // out or ref have to be duplicated here.
227 // Define parameters, and count out/ref parameters
229 Parameters end_parameters;
232 foreach (Parameter p in Parameters.FixedParameters) {
233 if ((p.ModFlags & Parameter.Modifier.ISBYREF) != 0)
237 if (out_params > 0) {
238 Type [] end_param_types = new Type [out_params];
239 Parameter [] end_params = new Parameter [out_params ];
242 for (int i = 0; i < Parameters.FixedParameters.Length; ++i) {
243 Parameter p = Parameters.FixedParameters [i];
244 if ((p.ModFlags & Parameter.Modifier.ISBYREF) == 0)
247 end_param_types [param] = p.ExternalType();
248 end_params [param] = p;
251 end_parameters = new Parameters (end_params, end_param_types);
254 end_parameters = Parameters.EmptyReadOnlyParameters;
257 end_parameters = Parameters.MergeGenerated (end_parameters,
258 new Parameter (TypeManager.iasyncresult_type, "result", Parameter.Modifier.NONE, null, Location));
261 // Create method, define parameters, register parameters with type system
263 EndInvokeBuilder = TypeBuilder.DefineMethod ("EndInvoke", mattr, cc, ret_type, end_parameters.Types);
264 EndInvokeBuilder.SetImplementationFlags (MethodImplAttributes.Runtime);
266 end_parameters.ApplyAttributes (EndInvokeBuilder);
267 TypeManager.RegisterMethod (EndInvokeBuilder, end_parameters);
272 public override void Emit ()
274 Parameters.ApplyAttributes (InvokeBuilder);
276 if (OptAttributes != null) {
277 OptAttributes.Emit ();
283 protected override TypeAttributes TypeAttr {
285 return Modifiers.TypeAttr (ModFlags, IsTopLevel) |
286 TypeAttributes.Class | TypeAttributes.Sealed |
291 public override string[] ValidAttributeTargets {
293 return attribute_targets;
298 protected override bool VerifyClsCompliance ()
300 if (!base.VerifyClsCompliance ()) {
304 Parameters.VerifyClsCompliance ();
306 if (!AttributeTester.IsClsCompliant (ReturnType.Type)) {
307 Report.Error (3002, Location, "Return type of `{0}' is not CLS-compliant", GetSignatureForError ());
313 // Returns the MethodBase for "Invoke" from a delegate type, this is used
314 // to extract the signature of a delegate.
316 public static MethodInfo GetInvokeMethod (Type container_type, Type delegate_type, Location loc)
318 Expression ml = Expression.MemberLookup (container_type, delegate_type,
321 if (!(ml is MethodGroupExpr)) {
322 Report.Error (-100, loc, "Internal error: could not find Invoke method!");
326 return (MethodInfo) (((MethodGroupExpr) ml).Methods [0]);
330 /// Verifies whether the method in question is compatible with the delegate
331 /// Returns the method itself if okay and null if not.
333 public static MethodBase VerifyMethod (Type container_type, Type delegate_type, MethodBase mb,
336 ParameterData pd = TypeManager.GetParameterData (mb);
338 int pd_count = pd.Count;
340 MethodBase invoke_mb = GetInvokeMethod (container_type, delegate_type, loc);
341 if (invoke_mb == null)
344 ParameterData invoke_pd = TypeManager.GetParameterData (invoke_mb);
346 if (invoke_pd.Count != pd_count)
349 for (int i = pd_count; i > 0; ) {
352 Type invoke_pd_type = invoke_pd.ParameterType (i);
353 Type pd_type = pd.ParameterType (i);
354 Parameter.Modifier invoke_pd_type_mod = invoke_pd.ParameterModifier (i);
355 Parameter.Modifier pd_type_mod = pd.ParameterModifier (i);
357 invoke_pd_type_mod &= ~Parameter.Modifier.PARAMS;
358 pd_type_mod &= ~Parameter.Modifier.PARAMS;
360 if (invoke_pd_type == pd_type &&
361 invoke_pd_type_mod == pd_type_mod)
364 if (invoke_pd_type.IsSubclassOf (pd_type) &&
365 invoke_pd_type_mod == pd_type_mod)
366 if (RootContext.Version == LanguageVersion.ISO_1) {
367 Report.FeatureIsNotStandardized (loc, "contravariance");
375 Type invoke_mb_retval = ((MethodInfo) invoke_mb).ReturnType;
376 Type mb_retval = ((MethodInfo) mb).ReturnType;
377 if (invoke_mb_retval == mb_retval)
380 if (mb_retval.IsSubclassOf (invoke_mb_retval))
381 if (RootContext.Version == LanguageVersion.ISO_1) {
382 Report.FeatureIsNotStandardized (loc, "covariance");
392 // Verifies whether the invocation arguments are compatible with the
393 // delegate's target method
395 public static bool VerifyApplicability (EmitContext ec, Type delegate_type,
396 ArrayList args, Location loc)
403 arg_count = args.Count;
405 Expression ml = Expression.MemberLookup (
406 ec.ContainerType, delegate_type, "Invoke", loc);
408 MethodGroupExpr me = ml as MethodGroupExpr;
410 Report.Error (-100, loc, "Internal error: could not find Invoke method!" + delegate_type);
414 MethodBase mb = me.Methods [0];
415 ParameterData pd = TypeManager.GetParameterData (mb);
417 int pd_count = pd.Count;
419 bool params_method = pd.HasParams;
420 bool is_params_applicable = false;
421 bool is_applicable = Invocation.IsApplicable (ec, args, arg_count, mb);
423 if (!is_applicable && params_method &&
424 Invocation.IsParamsMethodApplicable (ec, me, args, arg_count, ref mb))
425 is_applicable = is_params_applicable = true;
427 if (!is_applicable && !params_method && arg_count != pd_count) {
428 Report.Error (1593, loc, "Delegate `{0}' does not take `{1}' arguments",
429 TypeManager.CSharpName (delegate_type), arg_count.ToString ());
433 return Invocation.VerifyArgumentsCompat (
434 ec, args, arg_count, mb,
435 is_params_applicable || (!is_applicable && params_method),
436 delegate_type, false, loc);
440 /// Verifies whether the delegate in question is compatible with this one in
441 /// order to determine if instantiation from the same is possible.
443 public static bool VerifyDelegate (EmitContext ec, Type delegate_type, Location loc)
445 Expression ml = Expression.MemberLookup (
446 ec.ContainerType, delegate_type, "Invoke", loc);
448 if (!(ml is MethodGroupExpr)) {
449 Report.Error (-100, loc, "Internal error: could not find Invoke method!");
453 MethodBase mb = ((MethodGroupExpr) ml).Methods [0];
454 ParameterData pd = TypeManager.GetParameterData (mb);
456 Expression probe_ml = Expression.MemberLookup (
457 ec.ContainerType, delegate_type, "Invoke", loc);
459 if (!(probe_ml is MethodGroupExpr)) {
460 Report.Error (-100, loc, "Internal error: could not find Invoke method!");
464 MethodBase probe_mb = ((MethodGroupExpr) probe_ml).Methods [0];
465 ParameterData probe_pd = TypeManager.GetParameterData (probe_mb);
467 if (((MethodInfo) mb).ReturnType != ((MethodInfo) probe_mb).ReturnType)
470 if (pd.Count != probe_pd.Count)
473 for (int i = pd.Count; i > 0; ) {
476 if (pd.ParameterType (i) != probe_pd.ParameterType (i) ||
477 pd.ParameterModifier (i) != probe_pd.ParameterModifier (i))
484 public static string FullDelegateDesc (Type del_type, MethodBase mb, ParameterData pd)
486 StringBuilder sb = new StringBuilder ();
487 sb.Append (TypeManager.CSharpName (((MethodInfo) mb).ReturnType));
489 sb.Append (TypeManager.CSharpName (del_type));
490 sb.Append (pd.GetSignatureForError ());
491 return sb.ToString ();
494 // Hack around System.Reflection as found everywhere else
495 public override MemberList FindMembers (MemberTypes mt, BindingFlags bf,
496 MemberFilter filter, object criteria)
498 ArrayList members = new ArrayList (2);
500 if ((mt & MemberTypes.Constructor) != 0) {
501 if (ConstructorBuilder != null && filter (ConstructorBuilder, criteria))
502 members.Add (ConstructorBuilder);
505 if ((mt & MemberTypes.Method) != 0) {
506 if (InvokeBuilder != null)
507 if (filter (InvokeBuilder, criteria))
508 members.Add (InvokeBuilder);
510 if (BeginInvokeBuilder != null)
511 if (filter (BeginInvokeBuilder, criteria))
512 members.Add (BeginInvokeBuilder);
514 if (EndInvokeBuilder != null)
515 if (filter (EndInvokeBuilder, criteria))
516 members.Add (EndInvokeBuilder);
519 return new MemberList (members);
522 public override MemberCache MemberCache {
528 public Expression InstanceExpression {
530 return instance_expr;
533 instance_expr = value;
537 public MethodBase TargetMethod {
539 return delegate_method;
542 delegate_method = value;
546 public Type TargetReturnType {
552 public override AttributeTargets AttributeTargets {
554 return AttributeTargets.Delegate;
559 // Represents header string for documentation comment.
561 public override string DocCommentHeader {
568 // Base class for `NewDelegate' and `ImplicitDelegateCreation'
570 public abstract class DelegateCreation : Expression {
571 protected MethodBase constructor_method;
572 protected MethodBase delegate_method;
573 protected MethodGroupExpr method_group;
574 protected Expression delegate_instance_expression;
576 protected DelegateCreation () {}
578 public static void Error_NoMatchingMethodForDelegate (EmitContext ec, MethodGroupExpr mg, Type type, Location loc)
581 MethodInfo found_method = (MethodInfo)mg.Methods [0];
583 if (mg.Methods.Length > 1)
584 method_desc = found_method.Name;
586 method_desc = Invocation.FullMethodDesc (found_method);
588 Expression invoke_method = Expression.MemberLookup (
589 ec.ContainerType, type, "Invoke", MemberTypes.Method,
590 Expression.AllBindingFlags, loc);
591 MethodInfo method = ((MethodGroupExpr) invoke_method).Methods [0] as MethodInfo;
593 ParameterData param = TypeManager.GetParameterData (method);
594 string delegate_desc = Delegate.FullDelegateDesc (type, method, param);
596 if (method.ReturnType != found_method.ReturnType) {
597 Report.Error (407, loc, "`{0}' has the wrong return type to match the delegate `{1}'", method_desc, delegate_desc);
599 Report.Error (123, loc, "Method `{0}' does not match delegate `{1}'", method_desc, delegate_desc);
603 public override void Emit (EmitContext ec)
605 if (delegate_instance_expression == null || delegate_method.IsStatic)
606 ec.ig.Emit (OpCodes.Ldnull);
608 delegate_instance_expression.Emit (ec);
610 if (delegate_method.IsVirtual && !method_group.IsBase) {
611 ec.ig.Emit (OpCodes.Dup);
612 ec.ig.Emit (OpCodes.Ldvirtftn, (MethodInfo) delegate_method);
614 ec.ig.Emit (OpCodes.Ldftn, (MethodInfo) delegate_method);
615 ec.ig.Emit (OpCodes.Newobj, (ConstructorInfo) constructor_method);
618 protected bool ResolveConstructorMethod (EmitContext ec)
620 Expression ml = Expression.MemberLookupFinal(ec,
621 null, type, ".ctor", MemberTypes.Constructor, AllBindingFlags | BindingFlags.DeclaredOnly, loc);
623 if (!(ml is MethodGroupExpr)) {
624 Report.Error (-100, loc, "Internal error: Could not find delegate constructor!");
628 constructor_method = ((MethodGroupExpr) ml).Methods [0];
632 public static MethodBase ImplicitStandardConversionExists (MethodGroupExpr mg, Type targetType)
634 foreach (MethodInfo mi in mg.Methods){
635 MethodBase mb = Delegate.VerifyMethod (mg.DeclaringType, targetType, mi, Location.Null);
642 protected Expression ResolveMethodGroupExpr (EmitContext ec, MethodGroupExpr mg)
644 delegate_method = ImplicitStandardConversionExists (mg, type);
646 if (delegate_method == null) {
647 Error_NoMatchingMethodForDelegate (ec, mg, type, loc);
652 // Check safe/unsafe of the delegate
655 ParameterData param = TypeManager.GetParameterData (delegate_method);
656 int count = param.Count;
658 for (int i = 0; i < count; i++){
659 if (param.ParameterType (i).IsPointer){
660 Expression.UnsafeError (loc);
666 //TODO: implement caching when performance will be low
667 IMethodData md = TypeManager.GetMethod (delegate_method);
669 if (System.Attribute.GetCustomAttribute (delegate_method, TypeManager.conditional_attribute_type) != null) {
670 Report.SymbolRelatedToPreviousError (delegate_method);
671 Report.Error (1618, loc, "Cannot create delegate with `{0}' because it has a Conditional attribute", TypeManager.CSharpSignature (delegate_method));
675 md.SetMemberIsUsed ();
676 if (md.OptAttributes != null && md.OptAttributes.Search (TypeManager.conditional_attribute_type) != null) {
677 Report.SymbolRelatedToPreviousError (delegate_method);
678 Report.Error (1618, loc, "Cannot create delegate with `{0}' because it has a Conditional attribute", TypeManager.CSharpSignature (delegate_method));
683 if (mg.InstanceExpression != null)
684 delegate_instance_expression = mg.InstanceExpression.Resolve (ec);
685 else if (ec.IsStatic) {
686 if (!delegate_method.IsStatic) {
687 Report.Error (120, loc, "`{0}': An object reference is required for the nonstatic field, method or property",
688 TypeManager.CSharpSignature (delegate_method));
691 delegate_instance_expression = null;
693 delegate_instance_expression = ec.GetThis (loc);
695 if (delegate_instance_expression != null && delegate_instance_expression.Type.IsValueType)
696 delegate_instance_expression = new BoxedCast (
697 delegate_instance_expression, TypeManager.object_type);
700 eclass = ExprClass.Value;
706 // Created from the conversion code
708 public class ImplicitDelegateCreation : DelegateCreation {
710 ImplicitDelegateCreation (Type t, Location l)
716 public override Expression DoResolve (EmitContext ec)
721 static public Expression Create (EmitContext ec, MethodGroupExpr mge,
722 Type target_type, Location loc)
724 ImplicitDelegateCreation d = new ImplicitDelegateCreation (target_type, loc);
725 if (!d.ResolveConstructorMethod (ec))
728 return d.ResolveMethodGroupExpr (ec, mge);
733 // A delegate-creation-expression, invoked from the `New' class
735 public class NewDelegate : DelegateCreation {
736 public ArrayList Arguments;
739 // This constructor is invoked from the `New' expression
741 public NewDelegate (Type type, ArrayList Arguments, Location loc)
744 this.Arguments = Arguments;
748 public override Expression DoResolve (EmitContext ec)
750 if (Arguments == null || Arguments.Count != 1) {
751 Report.Error (149, loc,
752 "Method name expected");
756 if (!ResolveConstructorMethod (ec))
759 Argument a = (Argument) Arguments [0];
761 if (!a.ResolveMethodGroup (ec))
764 Expression e = a.Expr;
766 if (e is AnonymousMethod && RootContext.Version != LanguageVersion.ISO_1)
767 return ((AnonymousMethod) e).Compatible (ec, type);
769 MethodGroupExpr mg = e as MethodGroupExpr;
771 return ResolveMethodGroupExpr (ec, mg);
773 if (!TypeManager.IsDelegateType (e.Type)) {
774 Report.Error (149, loc, "Method name expected");
778 method_group = Expression.MemberLookup (
779 ec.ContainerType, type, "Invoke", MemberTypes.Method,
780 Expression.AllBindingFlags, loc) as MethodGroupExpr;
782 if (method_group == null) {
783 Report.Error (-200, loc, "Internal error ! Could not find Invoke method!");
787 // This is what MS' compiler reports. We could always choose
788 // to be more verbose and actually give delegate-level specifics
789 if (!Delegate.VerifyDelegate (ec, type, loc)) {
790 Report.Error (29, loc, "Cannot implicitly convert type '" + e.Type + "' " +
791 "to type '" + type + "'");
795 delegate_instance_expression = e;
796 delegate_method = method_group.Methods [0];
798 eclass = ExprClass.Value;
803 public class DelegateInvocation : ExpressionStatement {
805 public Expression InstanceExpr;
806 public ArrayList Arguments;
810 public DelegateInvocation (Expression instance_expr, ArrayList args, Location loc)
812 this.InstanceExpr = instance_expr;
813 this.Arguments = args;
817 public override Expression DoResolve (EmitContext ec)
819 if (InstanceExpr is EventExpr) {
821 EventInfo ei = ((EventExpr) InstanceExpr).EventInfo;
823 Expression ml = MemberLookup (
824 ec.ContainerType, ec.ContainerType, ei.Name,
825 MemberTypes.Event, AllBindingFlags | BindingFlags.DeclaredOnly, loc);
829 // If this is the case, then the Event does not belong
830 // to this Type and so, according to the spec
831 // cannot be accessed directly
833 // Note that target will not appear as an EventExpr
834 // in the case it is being referenced within the same type container;
835 // it will appear as a FieldExpr in that case.
838 Assign.error70 (ei, loc);
844 Type del_type = InstanceExpr.Type;
845 if (del_type == null)
848 if (Arguments != null){
849 foreach (Argument a in Arguments){
850 if (!a.Resolve (ec, loc))
855 if (!Delegate.VerifyApplicability (ec, del_type, Arguments, loc))
858 Expression lookup = Expression.MemberLookup (ec.ContainerType, del_type, "Invoke", loc);
859 if (!(lookup is MethodGroupExpr)) {
860 Report.Error (-100, loc, "Internal error: could not find Invoke method!");
864 method = ((MethodGroupExpr) lookup).Methods [0];
865 type = ((MethodInfo) method).ReturnType;
866 eclass = ExprClass.Value;
871 public override void Emit (EmitContext ec)
874 // Invocation on delegates call the virtual Invoke member
875 // so we are always `instance' calls
877 Invocation.EmitCall (ec, false, false, InstanceExpr, method, Arguments, loc);
880 public override void EmitStatement (EmitContext ec)
884 // Pop the return value if there is one
886 if (method is MethodInfo){
887 if (((MethodInfo) method).ReturnType != TypeManager.void_type)
888 ec.ig.Emit (OpCodes.Pop);