[corlib] Update SafeHandle dispose pattern to match .net. Fixes #25132
[mono.git] / mcs / mcs / lambda.cs
index c73a54a10e89d08133d2d5148b456e19f02e3bb2..7868c6a2c9d49b576a63cc69b088fd6e9c722a2d 100644 (file)
@@ -7,6 +7,7 @@
 // Dual licensed under the terms of the MIT X11 or GNU GPL
 //
 // Copyright 2007-2008 Novell, Inc
+// Copyright 2011 Xamarin Inc
 //
 
 #if STATIC
@@ -23,13 +24,8 @@ namespace Mono.CSharp {
                //    A list of Parameters (explicitly typed parameters)
                //    An ImplicitLambdaParameter
                //
-               public LambdaExpression (bool isAsync, Location loc)
-                       : base (isAsync, loc)
-               {
-               }
-
                public LambdaExpression (Location loc)
-                       : this (false, loc)
+                       : base (loc)
                {
                }
 
@@ -69,7 +65,7 @@ namespace Mono.CSharp {
                        AParametersCollection d_params = Delegate.GetParameters (delegateType);
 
                        if (HasExplicitParameters) {
-                               if (!VerifyExplicitParameters (ec, delegateType, d_params))
+                               if (!VerifyExplicitParameters (ec, tic, delegateType, d_params))
                                        return null;
 
                                return Parameters;
@@ -79,13 +75,13 @@ namespace Mono.CSharp {
                        // If L has an implicitly typed parameter list we make implicit parameters explicit
                        // Set each parameter of L is given the type of the corresponding parameter in D
                        //
-                       if (!VerifyParameterCompatibility (ec, delegateType, d_params, ec.IsInProbingMode))
+                       if (!VerifyParameterCompatibility (ec, tic, delegateType, d_params, ec.IsInProbingMode))
                                return null;
 
                        TypeSpec [] ptypes = new TypeSpec [Parameters.Count];
                        for (int i = 0; i < d_params.Count; i++) {
                                // D has no ref or out parameters
-                               if ((d_params.FixedParameters [i].ModFlags & Parameter.Modifier.ISBYREF) != 0)
+                               if ((d_params.FixedParameters[i].ModFlags & Parameter.Modifier.RefOutMask) != 0)
                                        return null;
 
                                TypeSpec d_param = d_params.Types [i];
@@ -128,6 +124,11 @@ namespace Mono.CSharp {
                {
                        return "lambda expression";
                }
+               
+               public override object Accept (StructuralVisitor visitor)
+               {
+                       return visitor.Visit (this);
+               }
        }
 
        class LambdaMethod : AnonymousMethodBody
@@ -181,7 +182,7 @@ namespace Mono.CSharp {
                ExpressionStatement statement;
 
                public ContextualReturn (Expression expr)
-                       : base (expr, expr.Location)
+                       : base (expr, expr.StartLocation)
                {
                }
 
@@ -190,15 +191,19 @@ namespace Mono.CSharp {
                        return Expr.CreateExpressionTree (ec);
                }
 
-               public override void Emit (EmitContext ec)
+               protected override void DoEmit (EmitContext ec)
                {
                        if (statement != null) {
                                statement.EmitStatement (ec);
-                               ec.Emit (OpCodes.Ret);
+                               if (unwind_protect)
+                                       ec.Emit (OpCodes.Leave, ec.CreateReturnLabel ());
+                               else {
+                                       ec.Emit (OpCodes.Ret);
+                               }
                                return;
                        }
 
-                       base.Emit (ec);
+                       base.DoEmit (ec);
                }
 
                protected override bool DoResolve (BlockContext ec)