2008-09-29 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mcs / mcs / linq.cs
index 1ea802af7c1b2da038c7eb089cf5ac052db6f507..610f0f499fc72ce6e4525d6a8b6d4845cbfe2b62 100644 (file)
@@ -39,8 +39,18 @@ namespace Mono.CSharp.Linq
 
                public override Expression DoResolve (EmitContext ec)
                {
+                       int counter = TransparentParameter.Counter;
+
                        Expression e = BuildQueryClause (ec, null, null, null);
                        e = e.Resolve (ec);
+
+                       //
+                       // Reset counter in probing mode to ensure that all transparent
+                       // identifier anonymous types are created only once
+                       //
+                       if (ec.IsInProbingMode)
+                               TransparentParameter.Counter = counter;
+
                        return e;
                }
 
@@ -90,7 +100,7 @@ namespace Mono.CSharp.Linq
                        public bool NoExactMatch (EmitContext ec, MethodBase method)
                        {
 #if GMCS_SOURCE                                
-                               ParameterData pd = TypeManager.GetParameterData (method);
+                               AParametersCollection pd = TypeManager.GetParameterData (method);
                                Type source_type = pd.ExtensionMethodType;
                                if (source_type != null) {
                                        Argument a = (Argument) Arguments [0];
@@ -197,7 +207,7 @@ namespace Mono.CSharp.Linq
                {
                        Parameters p = new Parameters (parameters);
 
-                       LambdaExpression selector = new LambdaExpression ((TypeContainer)ec.TypeContainer, p, loc);
+                       LambdaExpression selector = new LambdaExpression (p, loc);
                        selector.Block = new SelectorBlock (ec.CurrentBlock, p, ti, loc);
                        selector.Block.AddStatement (new ContextualReturn (expr));
 
@@ -211,6 +221,11 @@ namespace Mono.CSharp.Linq
 
                protected abstract string MethodName { get; }
 
+               public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
+               {
+                       // Nothing to mutate
+               }
+
                public virtual AQueryClause Next {
                        set {
                                next = value;
@@ -499,17 +514,16 @@ namespace Mono.CSharp.Linq
                                        //
                                        // Spread resolved initializer type
                                        //
-                                       parameter.ParameterType = type;
-                                       parameter.Resolve (ec);
+                                       ((ImplicitLambdaParameter) parameter).Type = type;
                                }
 
                                return e;
                        }
 
-                       protected override void Error_InvalidInitializer (Expression initializer)
+                       protected override void Error_InvalidInitializer (string initializer)
                        {
                                Report.Error (1932, loc, "A range variable `{0}' cannot be initialized with `{1}'",
-                                       Name, initializer.GetSignatureForError ());
+                                       Name, initializer);
                        }                       
                }
 
@@ -672,6 +686,11 @@ namespace Mono.CSharp.Linq
                        {
                                throw new NotSupportedException ();
                        }
+
+                       public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
+                       {
+                               throw new NotSupportedException ();
+                       }
                }
 
                public ImplicitQueryParameter (LocatedToken variable)
@@ -686,11 +705,11 @@ namespace Mono.CSharp.Linq
        //
        public class TransparentParameter : ImplicitLambdaParameter
        {
-               static int counter;
+               public static int Counter;
                const string ParameterNamePrefix = "<>__TranspIdent";
 
                public TransparentParameter (Location loc)
-                       : base (ParameterNamePrefix + counter++, loc)
+                       : base (ParameterNamePrefix + Counter++, loc)
                {
                }
        }