Expression ResolveAddressOf (ResolveContext ec)
{
- if (!ec.IsUnsafe)
+ if (ec.CurrentIterator != null) {
+ UnsafeInsideIteratorError (ec, loc);
+ } else if (!ec.IsUnsafe) {
UnsafeError (ec, loc);
+ }
Expr = Expr.DoResolveLValue (ec, EmptyExpression.UnaryAddress);
if (Expr == null || Expr.eclass != ExprClass.Variable) {
is_fixed = vr.IsFixed;
vr.SetHasAddressTaken ();
- if (vr.IsHoisted) {
+ if (vr.IsHoisted && ec.CurrentIterator == null) {
AnonymousMethodExpression.Error_AddressOfCapturedVar (ec, vr, loc);
}
} else {
if (expr == null)
return null;
- if (!ec.IsUnsafe)
+ if (ec.CurrentIterator != null) {
+ UnsafeInsideIteratorError (ec, loc);
+ } else if (!ec.IsUnsafe) {
UnsafeError (ec, loc);
+ }
var pc = expr.Type as PointerContainer;
return null;
}
- if (type.IsPointer && !ec.IsUnsafe) {
- UnsafeError (ec, loc);
+ if (type.IsPointer) {
+ if (ec.CurrentIterator != null) {
+ UnsafeInsideIteratorError (ec, loc);
+ } else if (!ec.IsUnsafe) {
+ UnsafeError (ec, loc);
+ }
}
eclass = ExprClass.Value;
public override Expression CreateExpressionTree (ResolveContext rc)
{
- rc.Report.Error (8046, loc, "An expression tree cannot contain a declaration expression");
+ rc.Report.Error (8198, loc, "An expression tree cannot contain out variable declaration");
return null;
}
bool DoResolveCommon (ResolveContext rc)
{
+ if (rc.HasAny (ResolveContext.Options.BaseInitializer | ResolveContext.Options.FieldInitializerScope)) {
+ rc.Report.Error (8200, loc, "Out variable and pattern variable declarations are not allowed within constructor initializers, field initializers, or property initializers");
+ } else if (rc.HasSet (ResolveContext.Options.QueryClauseScope)) {
+ rc.Report.Error (8201, loc, "Out variable and pattern variable declarations are not allowed within a query clause");
+ }
+
var var_expr = VariableType as VarExpr;
if (var_expr != null) {
type = InternalType.VarOutType;
public override Expression ConvertResult (ResolveContext ec, Binary b)
{
if (left != null) {
- b.left = EmptyCast.Create (b.left, left);
+ b.left = Convert.UserDefinedConversion (ec, b.left, left, Convert.UserConversionRestriction.ImplicitOnly, b.loc) ?? EmptyCast.Create (b.left, left);
} else if (right != null) {
- b.right = EmptyCast.Create (b.right, right);
+ b.right = Convert.UserDefinedConversion (ec, b.right, right, Convert.UserConversionRestriction.ImplicitOnly, b.loc) ?? EmptyCast.Create (b.right, right);
}
TypeSpec r_type = ReturnType;
}
}
- static CSharp.Operator.OpType ConvertBinaryToUserOperator (Operator op)
+ public static CSharp.Operator.OpType ConvertBinaryToUserOperator (Operator op)
{
switch (op) {
case Operator.Addition:
bool is_value_type = type.IsStructOrEnum;
VariableReference vr = target as VariableReference;
+ bool prepare_await = ec.HasSet (BuilderContext.Options.AsyncBody) && arguments?.ContainsEmitWithAwait () == true;
+
if (target != null && is_value_type && (vr != null || method == null)) {
+ if (prepare_await) {
+ arguments = arguments.Emit (ec, false, true);
+ prepare_await = false;
+ }
+
target.AddressOf (ec, AddressOp.Store);
} else if (vr != null && vr.IsRef) {
vr.EmitLoad (ec);
}
if (arguments != null) {
- if (ec.HasSet (BuilderContext.Options.AsyncBody) && (arguments.Count > (this is NewInitialize ? 0 : 1)) && arguments.ContainsEmitWithAwait ())
+ if (prepare_await)
arguments = arguments.Emit (ec, false, true);
arguments.Emit (ec);
}
type = ac.Element;
- if (type.IsPointer && !ec.IsUnsafe) {
- UnsafeError (ec, ea.Location);
+ if (type.IsPointer) {
+ if (ec.CurrentIterator != null) {
+ UnsafeInsideIteratorError (ec, ea.Location);
+ } else if (!ec.IsUnsafe) {
+ UnsafeError (ec, ea.Location);
+ }
}
if (conditional_access_receiver)
if (!(ec.CurrentMemberDefinition is Field) && !TypeManager.VerifyUnmanaged (ec.Module, type, loc))
return null;
- if (!ec.IsUnsafe) {
+ var rc = ec as ResolveContext;
+ if (rc?.CurrentIterator != null) {
+ UnsafeInsideIteratorError (ec.Module.Compiler.Report, loc);
+ } else if (!ec.IsUnsafe) {
UnsafeError (ec.Module.Compiler.Report, loc);
}
args);
}
- protected override Expression DoResolve (ResolveContext ec)
+ protected override Expression DoResolve (ResolveContext rc)
{
- Expression e = base.DoResolve (ec);
+ Expression e = base.DoResolve (rc);
if (type == null)
return null;
if (type.IsDelegate) {
- ec.Report.Error (1958, Initializers.Location,
+ rc.Report.Error (1958, Initializers.Location,
"Object and collection initializers cannot be used to instantiate a delegate");
}
- Expression previous = ec.CurrentInitializerVariable;
- ec.CurrentInitializerVariable = new InitializerTargetExpression (this);
- initializers.Resolve (ec);
- ec.CurrentInitializerVariable = previous;
+ Expression previous = rc.CurrentInitializerVariable;
+ rc.CurrentInitializerVariable = new InitializerTargetExpression (this);
+ using (rc.With (ResolveContext.Options.DontSetConditionalAccessReceiver, false)) {
+ initializers.Resolve (rc);
+ }
+ rc.CurrentInitializerVariable = previous;
dynamic = e as DynamicExpressionStatement;
if (dynamic != null)
return value;
}
}
+
+ class ThrowExpression : ExpressionStatement
+ {
+ Expression expr;
+
+ public ThrowExpression (Expression expr, Location loc)
+ {
+ this.expr = expr;
+ this.loc = loc;
+ }
+
+ protected override void CloneTo (CloneContext clonectx, Expression t)
+ {
+ var target = (ThrowExpression)t;
+ target.expr = expr.Clone (clonectx);
+ }
+
+ public override bool ContainsEmitWithAwait ()
+ {
+ return expr.ContainsEmitWithAwait ();
+ }
+
+ public override Expression CreateExpressionTree (ResolveContext rc)
+ {
+ rc.Report.Error (8188, loc, "An expression tree cannot not contain a throw expression");
+ return expr;
+ }
+
+ protected override Expression DoResolve (ResolveContext rc)
+ {
+ expr = expr.Resolve (rc, ResolveFlags.Type | ResolveFlags.VariableOrValue);
+
+ if (expr == null)
+ return null;
+
+ expr = Throw.ConvertType (rc, expr);
+
+ eclass = ExprClass.Value;
+ type = InternalType.ThrowExpr;
+ return this;
+ }
+
+ public override void Emit (EmitContext ec)
+ {
+ EmitStatement (ec);
+ }
+
+ public override void EmitStatement (EmitContext ec)
+ {
+ expr.Emit (ec);
+
+ ec.Emit (OpCodes.Throw);
+ }
+
+ public override void FlowAnalysis (FlowAnalysisContext fc)
+ {
+ expr.FlowAnalysis (fc);
+ }
+
+ public override Reachability MarkReachable (Reachability rc)
+ {
+ return Reachability.CreateUnreachable ();
+ }
+ }
}