// A list of Parameters (explicitly typed parameters)
// An ImplicitLambdaParameter
//
- public LambdaExpression (TypeContainer host, Parameters parameters, Location loc)
- : base (host, parameters, loc)
+ public LambdaExpression (Parameters parameters, Location loc)
+ : base (parameters, loc)
{
if (parameters.Count > 0)
explicit_parameters = !(parameters.FixedParameters [0] is ImplicitLambdaParameter);
if (!TypeManager.IsDelegateType (delegateType))
return null;
- ParameterData d_params = TypeManager.GetDelegateParameters (delegateType);
+ AParametersCollection d_params = TypeManager.GetDelegateParameters (delegateType);
if (explicit_parameters) {
if (!VerifyExplicitParameters (delegateType, d_params, ec.IsInProbingMode))
if (!VerifyParameterCompatibility (delegateType, d_params, ec.IsInProbingMode))
return null;
- if (Parameters.Types == null)
- Parameters.Types = new Type [Parameters.Count];
-
+ Type [] ptypes = new Type [Parameters.Count];
for (int i = 0; i < d_params.Count; i++) {
// D has no ref or out parameters
- if ((d_params.ParameterModifier (i) & Parameter.Modifier.ISBYREF) != 0)
+ if ((d_params.FixedParameters [i].ModFlags & Parameter.Modifier.ISBYREF) != 0)
return null;
Type d_param = d_params.Types [i];
if (d_param.IsGenericParameter)
d_param = delegateType.GetGenericArguments () [d_param.GenericParameterPosition];
#endif
- // When inferred context exists all generics parameters have type replacements
+ //
+ // When type inference context exists try to apply inferred type arguments
+ //
if (tic != null) {
d_param = tic.InflateGenericArgument (d_param);
}
- Parameters.Types [i] = Parameters.FixedParameters[i].ParameterType = d_param;
+ ptypes [i] = d_param;
+ ((ImplicitLambdaParameter) Parameters.FixedParameters [i]).Type = d_param;
}
+
+ Parameters.Types = ptypes;
return Parameters;
}
protected override AnonymousMethodBody CompatibleMethodFactory (Type returnType, Type delegateType, Parameters p, ToplevelBlock b)
{
- return new LambdaMethod (Host,
- p, b, returnType,
- delegateType, loc);
+ return new LambdaMethod (p, b, returnType, delegateType, loc);
}
public override string GetSignatureForError ()
public class LambdaMethod : AnonymousMethodBody
{
- public LambdaMethod (TypeContainer host, Parameters parameters,
+ public LambdaMethod (Parameters parameters,
ToplevelBlock block, Type return_type, Type delegate_type,
Location loc)
- : base (host, parameters, block,
- return_type, delegate_type, loc)
+ : base (parameters, block, return_type, delegate_type, loc)
{
}
public override Expression CreateExpressionTree (EmitContext ec)
{
- return Block.CreateExpressionTree (ec);
+ Expression args = parameters.CreateExpressionTree (ec, loc);
+ Expression expr = Block.CreateExpressionTree (ec);
+ if (expr == null)
+ return null;
+
+ ArrayList arguments = new ArrayList (2);
+ arguments.Add (new Argument (expr));
+ arguments.Add (new Argument (args));
+ return CreateExpressionFactoryCall ("Lambda",
+ new TypeArguments (loc, new TypeExpression (type, loc)),
+ arguments);
}
}
public override void Emit (EmitContext ec)
{
- if (ec.ReturnType == TypeManager.void_type)
+ if (ec.ReturnType == TypeManager.void_type) {
((ExpressionStatement) Expr).EmitStatement (ec);
- else
- base.Emit (ec);
+ ec.ig.Emit (OpCodes.Ret);
+ return;
+ }
+
+ base.Emit (ec);
}
protected override bool DoResolve (EmitContext ec)
if (Expr == null)
return false;
- if (Expr is ExpressionStatement) {
- if (Expr is Invocation)
- return TypeManager.IsEqual (Expr.Type, TypeManager.void_type);
+ if (Expr is ExpressionStatement)
return true;
- }
Expr.Error_InvalidExpressionStatement ();
return false;