return null;
Expression res = base.ResolveOperator (ec, unwrap);
+ if (res == null) {
+ Error_OperatorCannotBeApplied (ec, loc, OperName (Oper), Expr.Type);
+ return null;
+ }
+
if (res != this) {
if (user_operator == null)
return res;
{
if (rc.IsRuntimeBinder) {
if (UnwrapLeft == null && !Left.Type.IsNullableType)
- Left = Wrap.Create (Left, rc.Module.PredefinedTypes.Nullable.TypeSpec.MakeGenericType (rc.Module, new[] { Left.Type }));
+ Left = LiftOperand (rc, Left);
if (UnwrapRight == null && !Right.Type.IsNullableType)
- Right = Wrap.Create (Right, rc.Module.PredefinedTypes.Nullable.TypeSpec.MakeGenericType (rc.Module, new[] { Right.Type }));
+ Right = LiftOperand (rc, Right);
} else {
if (UnwrapLeft == null && Left != null && Left.Type.IsNullableType) {
Left = Unwrap.CreateUnwrapped (Left);
return this;
}
+ Expression LiftOperand (ResolveContext rc, Expression expr)
+ {
+ TypeSpec type;
+ if (expr.IsNull) {
+ type = Left.IsNull ? Right.Type : Left.Type;
+ } else {
+ type = expr.Type;
+ }
+
+ if (!type.IsNullableType)
+ type = rc.Module.PredefinedTypes.Nullable.TypeSpec.MakeGenericType (rc.Module, new[] { type });
+
+ return Wrap.Create (expr, type);
+ }
+
public override void Emit (EmitContext ec)
{
if (IsBitwiseBoolean && UserOperator == null) {
if (ec.HasSet (BuilderContext.Options.AsyncBody) && Binary.Right.ContainsEmitWithAwait ()) {
Left = Left.EmitToField (ec);
Right = Right.EmitToField (ec);
+ } else {
+ UnwrapLeft.Store (ec);
+ UnwrapRight.Store (ec);
}
Left.Emit (ec);
public override void FlowAnalysis (FlowAnalysisContext fc)
{
left.FlowAnalysis (fc);
+ var left_da = fc.BranchDefiniteAssignment ();
right.FlowAnalysis (fc);
+ fc.DefiniteAssignment = left_da;
}
protected override void CloneTo (CloneContext clonectx, Expression t)