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);
}
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;
//
type = InternalType.AnonymousMethod;
- if (!DoResolveParameters (ec))
+ if (!DoResolveParameters (rc))
return null;
return this;
Modifiers modifiers;
TypeDefinition parent = null;
TypeParameters hoisted_tparams = null;
+ ParametersCompiled method_parameters = parameters;
var src_block = Block.Original.Explicit;
if (src_block.HasCapturedVariable || src_block.HasCapturedThis) {
parent = storey = ec.CurrentAnonymousMethod.Storey;
modifiers = Modifiers.STATIC | Modifiers.PRIVATE;
+
+ //
+ // Convert generated method to closed delegate method where unused
+ // this argument is generated during compilation which speeds up dispatch
+ // by about 25%
+ //
+ // Unused as it breaks compatibility
+ //
+ // method_parameters = ParametersCompiled.Prefix (method_parameters,
+ // new Parameter (null, null, 0, null, loc), ec.Module.Compiler.BuiltinTypes.Object);
}
if (storey == null && hoisted_tparams == null)
return new AnonymousMethodMethod (parent,
this, storey, new TypeExpression (ReturnType, Location), modifiers,
- member_name, parameters);
+ member_name, method_parameters);
}
protected override Expression DoResolve (ResolveContext ec)
}
bool is_static = (method.ModFlags & Modifiers.STATIC) != 0;
- if (is_static && am_cache == null) {
+ if (is_static && am_cache == null && !ec.IsStaticConstructor) {
//
// Creates a field cache to store delegate instance if it's not generic
//