}
expr = new Compiler.Cast (new Compiler.TypeExpression (ctx.ImportType (ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null);
+ if ((flags & CSharpBinderFlags.CheckedContext) != 0)
+ expr = new Compiler.CheckedExpr (expr, Compiler.Location.Null);
+
var binder = new CSharpBinder (this, expr, errorSuggestion);
binder.AddRestrictions (target);
binder.AddRestrictions (value);
expr = new Compiler.Cast (new Compiler.TypeExpression (ctx.ImportType (ReturnType), Compiler.Location.Null), expr, Compiler.Location.Null);
+ if ((flags & CSharpBinderFlags.CheckedContext) != 0)
+ expr = new Compiler.CheckedExpr (expr, Compiler.Location.Null);
+
var binder = new CSharpBinder (this, expr, errorSuggestion);
binder.AddRestrictions (target);
binder.AddRestrictions (value);
protected override Expression ResolveConversions (ResolveContext ec)
{
- source = Convert.ExplicitConversion (ec, source, target.Type, loc);
- if (source != null)
- return this;
-
- return base.ResolveConversions (ec);
+ source = EmptyCast.Create (source, target.Type);
+ return this;
}
}
Arguments args = new Arguments (targs.Count + 1);
args.AddRange (targs);
args.Add (new Argument (source));
+
+ var binder_flags = CSharpBinderFlags.ValueFromCompoundAssignment;
+
+ //
+ // Compound assignment does target conversion using additional method
+ // call, set checked context as the binary operation can overflow
+ //
+ if (ec.HasSet (ResolveContext.Options.CheckedScope))
+ binder_flags |= CSharpBinderFlags.CheckedContext;
+
if (target is DynamicMemberBinder) {
- source = new DynamicMemberBinder (ma.Name, CSharpBinderFlags.ValueFromCompoundAssignment, args, loc).Resolve (ec);
+ source = new DynamicMemberBinder (ma.Name, binder_flags, args, loc).Resolve (ec);
// Handles possible event addition/subtraction
if (op == Binary.Operator.Addition || op == Binary.Operator.Subtraction) {
(ExpressionStatement) source, (ExpressionStatement) invoke, loc).Resolve (ec);
}
} else {
- source = new DynamicIndexBinder (CSharpBinderFlags.ValueFromCompoundAssignment, args, loc).Resolve (ec);
+ source = new DynamicIndexBinder (binder_flags, args, loc).Resolve (ec);
}
return source;
get { return 2; }
set { }
}
+
+ byte Byte = 200;
+ static dynamic V;
+ dynamic DynamicByte;
+ byte[] ByteArray = { 1, 100 };
public static int Main ()
{
try {
checked {
b += d;
- return 1;
+ return 3;
}
} catch (OverflowException) {
}
-
+
b += d;
+
+ try {
+ checked {
+ a.Byte += 100;
+ return 4;
+ }
+ } catch (OverflowException) {
+ }
+
+ a.Byte += 100;
+
+ checked {
+ d = byte.MaxValue;
+ d += 100;
+ }
+
+ checked {
+ V = byte.MaxValue;
+ V -= 300;
+ }
+
+ var t = new Test ();
+ t.DynamicByte = byte.MaxValue;
+ d = t;
+ checked {
+ d.DynamicByte -= 500;
+ }
+
+ if (t.DynamicByte != -245)
+ return 5;
+
+ try {
+ checked {
+ d.ByteArray[1] += 200;
+ return 6;
+ }
+ } catch (OverflowException) {
+ }
return 0;
}
-}
\ No newline at end of file
+}