// Dual licensed under the terms of the MIT X11 or GNU GPL
//
// Copyright 2007-2008 Novell, Inc
+// Copyright 2011 Xamarin Inc
//
#if STATIC
if (ec.IsInProbingMode)
return this;
- BlockContext bc = new BlockContext (ec.MemberContext, ec.ConstructorBlock, TypeManager.void_type) {
+ BlockContext bc = new BlockContext (ec.MemberContext, ec.ConstructorBlock, ec.BuiltinTypes.Void) {
CurrentAnonymousMethod = ec.CurrentAnonymousMethod
};
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;
// 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];
// When type inference context exists try to apply inferred type arguments
//
if (tic != null) {
- d_param = tic.InflateGenericArgument (d_param);
+ d_param = tic.InflateGenericArgument (ec, d_param);
}
ptypes [i] = d_param;
{
return "lambda expression";
}
+
+ public override object Accept (StructuralVisitor visitor)
+ {
+ return visitor.Visit (this);
+ }
}
class LambdaMethod : AnonymousMethodBody
ExpressionStatement statement;
public ContextualReturn (Expression expr)
- : base (expr, expr.Location)
+ : base (expr, expr.StartLocation)
{
}
public override Expression CreateExpressionTree (ResolveContext ec)
{
+ if (Expr is ReferenceExpression) {
+ ec.Report.Error (8155, Expr.Location, "Lambda expressions that return by reference cannot be converted to expression trees");
+ return null;
+ }
+
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)
//
// When delegate returns void, only expression statements can be used
//
- if (ec.ReturnType == TypeManager.void_type) {
+ if (ec.ReturnType.Kind == MemberKind.Void) {
Expr = Expr.Resolve (ec);
if (Expr == null)
return false;
+ if (Expr is ReferenceExpression) {
+ // CSC: should be different error code
+ ec.Report.Error (8149, loc, "By-reference returns can only be used in lambda expressions that return by reference");
+ return false;
+ }
+
statement = Expr as ExpressionStatement;
- if (statement == null)
- Expr.Error_InvalidExpressionStatement (ec);
+ if (statement == null) {
+ var reduced = Expr as IReducedExpressionStatement;
+ if (reduced != null) {
+ statement = EmptyExpressionStatement.Instance;
+ } else {
+ Expr.Error_InvalidExpressionStatement (ec);
+ }
+ }
return true;
}