[mcs] Initial by ref returns and variables support
[mono.git] / mcs / mcs / argument.cs
index 00fd56d8a64a23743451fc6b829f07abe77f3cec..8421b4dfbfcc766e11af46e124c59be508d68165 100644 (file)
@@ -104,12 +104,17 @@ namespace Mono.CSharp
                        return Clone (Expr.Clone (clonectx));
                }
 
-               public virtual Expression CreateExpressionTree (ResolveContext ec)
+               public virtual Expression CreateExpressionTree (ResolveContext rc)
                {
+                       if (Type.Kind == MemberKind.ByRef) {
+                               rc.Report.Error (8153, Expr.Location, "An expression tree lambda cannot contain a call to a method, property, or indexer that returns by reference");
+                               return null;
+                       }
+
                        if (ArgType == AType.Default)
-                               ec.Report.Error (854, Expr.Location, "An expression tree cannot contain an invocation which uses optional parameter");
+                               rc.Report.Error (854, Expr.Location, "An expression tree cannot contain an invocation which uses optional parameter");
 
-                       return Expr.CreateExpressionTree (ec);
+                       return Expr.CreateExpressionTree (rc);
                }
 
 
@@ -126,12 +131,16 @@ namespace Mono.CSharp
                                return;
                        }
 
+                       if (Expr.Type.Kind == MemberKind.ByRef) {
+                               Expr.Emit (ec);
+                               return;
+                       }
+
                        AddressOp mode = AddressOp.Store;
                        if (ArgType == AType.Ref)
                                mode |= AddressOp.Load;
 
-                       IMemoryLocation ml = (IMemoryLocation) Expr;
-                       ml.AddressOf (ec, mode);
+                       ((IMemoryLocation)Expr).AddressOf (ec, mode);
                }
 
                public Argument EmitToField (EmitContext ec, bool cloneResult)
@@ -421,17 +430,19 @@ namespace Mono.CSharp
                        return all;
                }
 
-               public static Arguments CreateForExpressionTree (ResolveContext ec, Arguments args, params Expression[] e)
+               public static Arguments CreateForExpressionTree (ResolveContext rc, Arguments args, params Expression[] e)
                {
                        Arguments all = new Arguments ((args == null ? 0 : args.Count) + e.Length);
                        for (int i = 0; i < e.Length; ++i) {
-                               if (e [i] != null)
-                                       all.Add (new Argument (e[i]));
+                               var expr = e [i];
+                               if (expr != null) {
+                                       all.Add (new Argument (expr));
+                               }
                        }
 
                        if (args != null) {
                                foreach (Argument a in args.args) {
-                                       Expression tree_arg = a.CreateExpressionTree (ec);
+                                       Expression tree_arg = a.CreateExpressionTree (rc);
                                        if (tree_arg != null)
                                                all.Add (new Argument (tree_arg));
                                }