[Microsoft.Build.Tasks] Fix a net 2.0 failure.
[mono.git] / mcs / mcs / anonymous.cs
index 6c6acacf683dac66fbd883661c13883bd60cb83e..b20608ea52def25fa65d522c58746fbab1a0e59e 100644 (file)
@@ -352,7 +352,7 @@ namespace Mono.CSharp {
                                hoisted_locals.Add (hoisted);
                        }
 
-                       if (ec.CurrentBlock.Explicit != localVariable.Block.Explicit && !(hoisted.Storey is StateMachine))
+                       if (ec.CurrentBlock.Explicit != localVariable.Block.Explicit && !(hoisted.Storey is StateMachine) && hoisted.Storey != null)
                                hoisted.Storey.AddReferenceFromChildrenBlock (ec.CurrentBlock.Explicit);
                }
 
@@ -1321,16 +1321,28 @@ namespace Mono.CSharp {
                        return Parameters;
                }
 
-               protected override Expression DoResolve (ResolveContext ec)
+               protected override Expression DoResolve (ResolveContext rc)
                {
-                       if (ec.HasSet (ResolveContext.Options.ConstantScope)) {
-                               ec.Report.Error (1706, loc, "Anonymous methods and lambda expressions cannot be used in the current context");
+                       if (rc.HasSet (ResolveContext.Options.ConstantScope)) {
+                               rc.Report.Error (1706, loc, "Anonymous methods and lambda expressions cannot be used in the current context");
                                return null;
                        }
 
                        //
-                       // Set class type, set type
+                       // Update top-level block generated duting parsing with actual top-level block
                        //
+                       if (rc.HasAny (ResolveContext.Options.FieldInitializerScope | ResolveContext.Options.BaseInitializer) && rc.CurrentMemberDefinition.Parent.PartialContainer.PrimaryConstructorParameters != null) {
+                               var tb = rc.ConstructorBlock.ParametersBlock.TopBlock;
+                               if (Block.TopBlock != tb) {
+                                       Block b = Block;
+                                       while (b.Parent != Block.TopBlock && b != Block.TopBlock)
+                                               b = b.Parent;
+
+                                       b.Parent = tb;
+                                       tb.IncludeBlock (Block, Block.TopBlock);
+                                       b.ParametersBlock.TopBlock = tb;
+                               }
+                       }
 
                        eclass = ExprClass.Value;
 
@@ -1341,7 +1353,7 @@ namespace Mono.CSharp {
                        // 
                        type = InternalType.AnonymousMethod;
 
-                       if (!DoResolveParameters (ec))
+                       if (!DoResolveParameters (rc))
                                return null;
 
                        return this;
@@ -1780,11 +1792,9 @@ namespace Mono.CSharp {
                                // this argument is generated during compilation which speeds up dispatch
                                // by about 25%
                                //
-
-                               //
-                               // Disabled for now due to JIT bug
+                               // Unused as it breaks compatibility
                                //
-                               //method_parameters = ParametersCompiled.Prefix (method_parameters,
+                               // method_parameters = ParametersCompiled.Prefix (method_parameters,
                                //      new Parameter (null, null, 0, null, loc), ec.Module.Compiler.BuiltinTypes.Object);
                        }