Fixed string null constant conversion to object constant
[mono.git] / mcs / mcs / nullable.cs
index 967673bfe8abac6ff7abdb651259fb978a12e51b..96afce4fd5e97dbae1cc006bc78343b9d10bdb4a 100644 (file)
@@ -9,9 +9,11 @@
 //
 // Copyright 2001, 2002, 2003 Ximian, Inc (http://www.ximian.com)
 // Copyright 2004-2008 Novell, Inc
+// Copyright 2011 Xamarin Inc
 //
 
 using System;
+using SLE = System.Linq.Expressions;
 
 #if STATIC
 using IKVM.Reflection.Emit;
@@ -23,29 +25,27 @@ namespace Mono.CSharp.Nullable
 {
        public class NullableType : TypeExpr
        {
-               TypeExpr underlying;
+               readonly TypeSpec underlying;
 
-               public NullableType (TypeExpr underlying, Location l)
+               public NullableType (TypeSpec type, Location loc)
                {
-                       this.underlying = underlying;
-                       loc = l;
-
-                       eclass = ExprClass.Type;
+                       this.underlying = type;
+                       this.loc = loc;
                }
 
-               public NullableType (TypeSpec type, Location loc)
-                       : this (new TypeExpression (type, loc), loc)
-               { }
-
-               protected override TypeExpr DoResolveAsTypeStep (IMemberContext ec)
+               public override TypeSpec ResolveAsType (IMemberContext ec)
                {
-                       var type = ec.Module.PredefinedTypes.Nullable.Resolve (loc);
-                       if (type == null)
+                       eclass = ExprClass.Type;
+
+                       var otype = ec.Module.PredefinedTypes.Nullable.Resolve ();
+                       if (otype == null)
                                return null;
 
-                       TypeArguments args = new TypeArguments (underlying);
-                       GenericTypeExpr ctype = new GenericTypeExpr (type, args, loc);
-                       return ctype.ResolveAsTypeTerminal (ec, false);
+                       TypeArguments args = new TypeArguments (new TypeExpression (underlying, loc));
+                       GenericTypeExpr ctype = new GenericTypeExpr (otype, args, loc);
+                       
+                       type = ctype.ResolveAsType (ec);
+                       return type;
                }
        }
 
@@ -69,6 +69,9 @@ namespace Mono.CSharp.Nullable
                                MemberFilter.Method ("GetValueOrDefault", 0, ParametersCompiled.EmptyReadOnlyParameters, null), BindingRestriction.None);
                }
 
+               //
+               // Don't use unless really required for correctness, see Unwrap::Emit
+               //
                public static MethodSpec GetValue (TypeSpec nullableType)
                {
                        return (MethodSpec) MemberCache.FindMember (nullableType,
@@ -79,16 +82,23 @@ namespace Mono.CSharp.Nullable
                {
                        return ((InflatedTypeSpec) nullableType).TypeArguments[0];
                }
+
+               public static TypeSpec GetEnumUnderlyingType (ModuleContainer module, TypeSpec nullableEnum)
+               {
+                       return module.PredefinedTypes.Nullable.TypeSpec.MakeGenericType (module,
+                               new[] { EnumSpec.GetUnderlyingType (GetUnderlyingType (nullableEnum)) });
+               }
        }
 
-       public class Unwrap : Expression, IMemoryLocation, IAssignMethod
+       public class Unwrap : Expression, IMemoryLocation
        {
                Expression expr;
 
                LocalTemporary temp;
+               Expression temp_field;
                readonly bool useDefaultValue;
 
-               Unwrap (Expression expr, bool useDefaultValue)
+               public Unwrap (Expression expr, bool useDefaultValue = true)
                {
                        this.expr = expr;
                        this.loc = expr.Location;
@@ -98,6 +108,12 @@ namespace Mono.CSharp.Nullable
                        eclass = expr.eclass;
                }
 
+               public override bool ContainsEmitWithAwait ()
+               {
+                       return expr.ContainsEmitWithAwait ();
+               }
+
+               // TODO: REMOVE
                public static Expression Create (Expression expr)
                {
                        //
@@ -110,6 +126,18 @@ namespace Mono.CSharp.Nullable
                        return Create (expr, false);
                }
 
+               public static Expression CreateUnwrapped (Expression expr)
+               {
+                       //
+                       // Avoid unwraping and wraping of same type
+                       //
+                       Wrap wrap = expr as Wrap;
+                       if (wrap != null)
+                               return wrap.Child;
+
+                       return Create (expr, true);
+               }
+
                public static Unwrap Create (Expression expr, bool useDefaultValue)
                {
                        return new Unwrap (expr, useDefaultValue);
@@ -134,16 +162,37 @@ namespace Mono.CSharp.Nullable
                public override void Emit (EmitContext ec)
                {
                        Store (ec);
+
+                       var call = new CallEmitter ();
+                       call.InstanceExpression = this;
+
+                       //
+                       // Using GetGetValueOrDefault is prefered because JIT can possibly
+                       // inline it whereas Value property contains a throw which is very
+                       // unlikely to be inlined
+                       //
                        if (useDefaultValue)
-                               Invocation.EmitCall (ec, this, NullableInfo.GetGetValueOrDefault (expr.Type), null, loc);
+                               call.EmitPredefined (ec, NullableInfo.GetGetValueOrDefault (expr.Type), null);
                        else
-                               Invocation.EmitCall (ec, this, NullableInfo.GetValue (expr.Type), null, loc);
+                               call.EmitPredefined (ec, NullableInfo.GetValue (expr.Type), null);
                }
 
                public void EmitCheck (EmitContext ec)
                {
                        Store (ec);
-                       Invocation.EmitCall (ec, this, NullableInfo.GetHasValue (expr.Type), null, loc);
+
+                       var call = new CallEmitter ();
+                       call.InstanceExpression = this;
+
+                       call.EmitPredefined (ec, NullableInfo.GetHasValue (expr.Type), null);
+               }
+
+               public override Expression EmitToField (EmitContext ec)
+               {
+                       if (temp_field == null)
+                               temp_field = this.expr.EmitToField (ec);
+                       
+                       return this;
                }
 
                public override bool Equals (object obj)
@@ -169,12 +218,12 @@ namespace Mono.CSharp.Nullable
                        }
                }
 
-               void Store (EmitContext ec)
+               public void Store (EmitContext ec)
                {
-                       if (expr is VariableReference)
+                       if (temp != null || temp_field != null)
                                return;
 
-                       if (temp != null)
+                       if (expr is VariableReference)
                                return;
 
                        expr.Emit (ec);
@@ -183,20 +232,35 @@ namespace Mono.CSharp.Nullable
 
                public void Load (EmitContext ec)
                {
-                       if (expr is VariableReference)
+                       if (temp_field != null)
+                               temp_field.Emit (ec);
+                       else if (expr is VariableReference)
                                expr.Emit (ec);
                        else
                                LocalVariable.Emit (ec);
                }
 
-               public override System.Linq.Expressions.Expression MakeExpression (BuilderContext ctx)
+               public override SLE.Expression MakeExpression (BuilderContext ctx)
                {
                        return expr.MakeExpression (ctx);
                }
 
                public void AddressOf (EmitContext ec, AddressOp mode)
                {
-                       IMemoryLocation ml = expr as VariableReference;
+                       IMemoryLocation ml;
+
+                       if (temp_field != null) {
+                               ml = temp_field as IMemoryLocation;
+                               if (ml == null) {
+                                       var lt = new LocalTemporary (temp_field.Type);
+                                       temp_field.Emit (ec);
+                                       lt.Store (ec);
+                                       ml = lt;
+                               }
+                       } else {
+                               ml = expr as VariableReference;
+                       }
+
                        if (ml != null)
                                ml.AddressOf (ec, mode);
                        else
@@ -208,56 +272,11 @@ namespace Mono.CSharp.Nullable
                //
                LocalTemporary LocalVariable {
                        get {
-                               if (temp == null)
+                               if (temp == null && temp_field == null)
                                        temp = new LocalTemporary (expr.Type);
                                return temp;
                        }
                }
-
-               public void Emit (EmitContext ec, bool leave_copy)
-               {
-                       if (leave_copy)
-                               Load (ec);
-
-                       Emit (ec);
-               }
-
-               public void EmitAssign (EmitContext ec, Expression source,
-                                       bool leave_copy, bool prepare_for_load)
-               {
-                       InternalWrap wrap = new InternalWrap (source, expr.Type, loc);
-                       ((IAssignMethod) expr).EmitAssign (ec, wrap, leave_copy, false);
-               }
-
-               class InternalWrap : Expression
-               {
-                       public Expression expr;
-
-                       public InternalWrap (Expression expr, TypeSpec type, Location loc)
-                       {
-                               this.expr = expr;
-                               this.loc = loc;
-                               this.type = type;
-
-                               eclass = ExprClass.Value;
-                       }
-
-                       public override Expression CreateExpressionTree (ResolveContext ec)
-                       {
-                               throw new NotSupportedException ("ET");
-                       }
-
-                       protected override Expression DoResolve (ResolveContext ec)
-                       {
-                               return this;
-                       }
-
-                       public override void Emit (EmitContext ec)
-                       {
-                               expr.Emit (ec);
-                               ec.Emit (OpCodes.Newobj, NullableInfo.GetConstructor (type));
-                       }
-               }
        }
 
        //
@@ -282,7 +301,9 @@ namespace Mono.CSharp.Nullable
 
                public override void Emit (EmitContext ec)
                {
-                       Invocation.EmitCall (ec, Child, NullableInfo.GetValue (Child.Type), null, loc);
+                       var call = new CallEmitter ();
+                       call.InstanceExpression = Child;
+                       call.EmitPredefined (ec, NullableInfo.GetValue (Child.Type), null);
                }
        }
 
@@ -302,6 +323,12 @@ namespace Mono.CSharp.Nullable
                                return child_cast.CreateExpressionTree (ec);
                        }
 
+                       var user_cast = child as UserCast;
+                       if (user_cast != null) {
+                               child.Type = type;
+                               return user_cast.CreateExpressionTree (ec);
+                       }
+
                        return base.CreateExpressionTree (ec);
                }
 
@@ -340,10 +367,12 @@ namespace Mono.CSharp.Nullable
                        return new LiftedNull (nullable, loc);
                }
 
-               public static Constant CreateFromExpression (ResolveContext ec, Expression e)
+               public static Constant CreateFromExpression (ResolveContext rc, Expression e)
                {
-                       ec.Report.Warning (458, 2, e.Location, "The result of the expression is always `null' of type `{0}'",
-                               TypeManager.CSharpName (e.Type));
+                       if (!rc.HasSet (ResolveContext.Options.ExpressionTreeConversion)) {
+                               rc.Report.Warning (458, 2, e.Location, "The result of the expression is always `null' of type `{0}'",
+                                       e.Type.GetSignatureForError ());
+                       }
 
                        return ReducedExpression.Create (Create (e.Type, e.Location), e);
                }
@@ -356,6 +385,7 @@ namespace Mono.CSharp.Nullable
                        value_target.AddressOf (ec, AddressOp.Store);
                        ec.Emit (OpCodes.Initobj, type);
                        value_target.Emit (ec);
+                       value_target.Release (ec);
                }
 
                public void AddressOf (EmitContext ec, AddressOp Mode)
@@ -371,12 +401,12 @@ namespace Mono.CSharp.Nullable
        //
        // Generic lifting expression, supports all S/S? -> T/T? cases
        //
-       public class Lifted : Expression, IMemoryLocation
+       public class LiftedConversion : Expression, IMemoryLocation
        {
                Expression expr, null_value;
                Unwrap unwrap;
 
-               public Lifted (Expression expr, Unwrap unwrap, TypeSpec type)
+               public LiftedConversion (Expression expr, Unwrap unwrap, TypeSpec type)
                {
                        this.expr = expr;
                        this.unwrap = unwrap;
@@ -384,10 +414,15 @@ namespace Mono.CSharp.Nullable
                        this.type = type;
                }
 
-               public Lifted (Expression expr, Expression unwrap, TypeSpec type)
+               public LiftedConversion (Expression expr, Expression unwrap, TypeSpec type)
                        : this (expr, unwrap as Unwrap, type)
                {
                }
+
+               public override bool ContainsEmitWithAwait ()
+               {
+                       return unwrap.ContainsEmitWithAwait ();
+               }
                
                public override Expression CreateExpressionTree (ResolveContext ec)
                {
@@ -410,12 +445,14 @@ namespace Mono.CSharp.Nullable
 
                        // Wrap target for T?
                        if (type.IsNullableType) {
-                               expr = Wrap.Create (expr, type);
-                               if (expr == null)
-                                       return null;
+                               if (!expr.Type.IsNullableType) {
+                                       expr = Wrap.Create (expr, type);
+                                       if (expr == null)
+                                               return null;
+                               }
 
                                null_value = LiftedNull.Create (type, loc);
-                       } else if (TypeManager.IsValueType (type)) {
+                       } else if (TypeSpec.IsValueType (type)) {
                                null_value = LiftedNull.Create (type, loc);
                        } else {
                                null_value = new NullConstant (type, loc);
@@ -439,6 +476,7 @@ namespace Mono.CSharp.Nullable
                        ec.MarkLabel (is_null_label);
 
                        null_value.Emit (ec);
+
                        ec.MarkLabel (end_label);
                }
 
@@ -519,11 +557,10 @@ namespace Mono.CSharp.Nullable
                        ec.MarkLabel (end_label);
                }
 
-               Expression LiftExpression (ResolveContext ec, Expression expr)
+               static Expression LiftExpression (ResolveContext ec, Expression expr)
                {
-                       TypeExpr lifted_type = new NullableType (expr.Type, expr.Location);
-                       lifted_type = lifted_type.ResolveAsTypeTerminal (ec, false);
-                       if (lifted_type == null)
+                       var lifted_type = new NullableType (expr.Type, expr.Location);
+                       if (lifted_type.ResolveAsType (ec) == null)
                                return null;
 
                        expr.Type = lifted_type.Type;
@@ -558,459 +595,424 @@ namespace Mono.CSharp.Nullable
                }
        }
 
-       public class LiftedBinaryOperator : Binary
+       //
+       // Lifted version of binary operators
+       //
+       class LiftedBinaryOperator : Expression
        {
-               Unwrap left_unwrap, right_unwrap;
-               Expression left_orig, right_orig;
-               Expression user_operator;
-               MethodSpec wrap_ctor;
-
-               public LiftedBinaryOperator (Binary.Operator op, Expression left, Expression right, Location loc)
-                       : base (op, left, right, loc)
+               public LiftedBinaryOperator (Binary b)
                {
+                       this.Binary = b;
+                       this.loc = b.Location;
                }
 
-               bool IsBitwiseBoolean {
-                       get {
-                               return (Oper == Operator.BitwiseAnd || Oper == Operator.BitwiseOr) &&
-                               ((left_unwrap != null && left_unwrap.Type.BuildinType == BuildinTypeSpec.Type.Bool) ||
-                                (right_unwrap != null && right_unwrap.Type.BuildinType == BuildinTypeSpec.Type.Bool));
-                       }
-               }
+               public Binary Binary { get; private set; }
 
-               bool IsLeftNullLifted {
-                       get {
-                               return (state & State.LeftNullLifted) != 0;
-                       }
-               }
+               public Expression Left { get; set; }
 
-               bool IsRightNullLifted {
+               public Expression Right { get; set; }
+
+               public Unwrap UnwrapLeft { get; set; }
+
+               public Unwrap UnwrapRight { get; set; }
+
+               public MethodSpec UserOperator { get; set; }
+
+               bool IsBitwiseBoolean {
                        get {
-                               return (state & State.RightNullLifted) != 0;
+                               return (Binary.Oper == Binary.Operator.BitwiseAnd || Binary.Oper == Binary.Operator.BitwiseOr) &&
+                               ((UnwrapLeft != null && UnwrapLeft.Type.BuiltinType == BuiltinTypeSpec.Type.Bool) ||
+                                (UnwrapRight != null && UnwrapRight.Type.BuiltinType == BuiltinTypeSpec.Type.Bool));
                        }
                }
 
-               public override Expression CreateExpressionTree (ResolveContext ec)
+               public override bool ContainsEmitWithAwait ()
                {
-                       if (user_operator != null)
-                               return user_operator.CreateExpressionTree (ec);
-
-                       return base.CreateExpressionTree (ec);
+                       return Left.ContainsEmitWithAwait () || Right.ContainsEmitWithAwait ();
                }
 
-               //
-               // CSC 2 has this behavior, it allows structs to be compared
-               // with the null literal *outside* of a generics context and
-               // inlines that as true or false.
-               //
-               Constant CreateNullConstant (ResolveContext ec, Expression expr)
+               public override Expression CreateExpressionTree (ResolveContext rc)
                {
-                       // FIXME: Handle side effect constants
-                       Constant c = new BoolConstant (ec.BuildinTypes, Oper == Operator.Inequality, loc);
+                       if (UserOperator != null) {
+                               Arguments args = new Arguments (2);
+                               args.Add (new Argument (Binary.Left));
+                               args.Add (new Argument (Binary.Right));
 
-                       if ((Oper & Operator.EqualityMask) != 0) {
-                               ec.Report.Warning (472, 2, loc, "The result of comparing value type `{0}' with null is `{1}'",
-                                       TypeManager.CSharpName (expr.Type), c.GetValueAsLiteral ());
-                       } else {
-                               ec.Report.Warning (464, 2, loc, "The result of comparing type `{0}' with null is always `{1}'",
-                                       TypeManager.CSharpName (expr.Type), c.GetValueAsLiteral ());
+                               var method = new UserOperatorCall (UserOperator, args, Binary.CreateExpressionTree, loc);
+                               return method.CreateExpressionTree (rc);
                        }
 
-                       return ReducedExpression.Create (c, this);
+                       return Binary.CreateExpressionTree (rc);
                }
 
-               protected override Expression DoResolve (ResolveContext ec)
+               protected override Expression DoResolve (ResolveContext rc)
                {
-                       if ((Oper & Operator.LogicalMask) != 0) {
-                               Error_OperatorCannotBeApplied (ec, left, right);
-                               return null;
-                       }
+                       if (rc.IsRuntimeBinder) {
+                               if (UnwrapLeft == null && !Left.Type.IsNullableType)
+                                       Left = Wrap.Create (Left, rc.Module.PredefinedTypes.Nullable.TypeSpec.MakeGenericType (rc.Module, new[] { Left.Type }));
 
-                       bool use_default_call = (Oper & (Operator.BitwiseMask | Operator.EqualityMask)) != 0;
-                       left_orig = left;
-                       if (left.Type.IsNullableType) {
-                               left = left_unwrap = Unwrap.Create (left, use_default_call);
-                               if (left == null)
-                                       return null;
-                       }
+                               if (UnwrapRight == null && !Right.Type.IsNullableType)
+                                       Right = Wrap.Create (Right, rc.Module.PredefinedTypes.Nullable.TypeSpec.MakeGenericType (rc.Module, new[] { Right.Type }));
+                       } else {
+                               if (UnwrapLeft == null && Left != null && Left.Type.IsNullableType) {
+                                       Left = Unwrap.CreateUnwrapped (Left);
+                                       UnwrapLeft = Left as Unwrap;
+                               }
 
-                       right_orig = right;
-                       if (right.Type.IsNullableType) {
-                               right = right_unwrap = Unwrap.Create (right, use_default_call);
-                               if (right == null)
-                                       return null;
+                               if (UnwrapRight == null && Right != null && Right.Type.IsNullableType) {
+                                       Right = Unwrap.CreateUnwrapped (Right);
+                                       UnwrapRight = Right as Unwrap;
+                               }
                        }
 
-                       //
-                       // Some details are in 6.4.2, 7.2.7
-                       // Arguments can be lifted for equal operators when the return type is bool and both
-                       // arguments are of same type
-                       //      
-                       if (left_orig is NullLiteral) {
-                               left = right;
-                               state |= State.LeftNullLifted;
-                               type = ec.BuildinTypes.Bool;
-                       }
+                       type = Binary.Type;
+                       eclass = Binary.eclass; 
 
-                       if (right_orig.IsNull) {
-                               if ((Oper & Operator.ShiftMask) != 0)
-                                       right = new EmptyExpression (ec.BuildinTypes.Int);
-                               else
-                                       right = left;
+                       return this;
+               }
 
-                               state |= State.RightNullLifted;
-                               type = ec.BuildinTypes.Bool;
+               public override void Emit (EmitContext ec)
+               {
+                       if (IsBitwiseBoolean && UserOperator == null) {
+                               EmitBitwiseBoolean (ec);
+                               return;
                        }
 
-                       eclass = ExprClass.Value;
-                       return DoResolveCore (ec, left_orig, right_orig);
-               }
+                       if ((Binary.Oper & Binary.Operator.EqualityMask) != 0) {
+                               EmitEquality (ec);
+                               return;
+                       }
 
-               void EmitBitwiseBoolean (EmitContext ec)
-               {
-                       Label load_left = ec.DefineLabel ();
-                       Label load_right = ec.DefineLabel ();
+                       Label is_null_label = ec.DefineLabel ();
                        Label end_label = ec.DefineLabel ();
 
-                       // null & value, null | value
-                       if (left_unwrap == null) {
-                               left_unwrap = right_unwrap;
-                               right_unwrap = null;
-                               right = left;
+                       if (ec.HasSet (BuilderContext.Options.AsyncBody) && Right.ContainsEmitWithAwait ()) {
+                               Left = Left.EmitToField (ec);
+                               Right = Right.EmitToField (ec);
                        }
 
-                       left_unwrap.Emit (ec);
-                       ec.Emit (OpCodes.Brtrue_S, load_right);
+                       if (UnwrapLeft != null) {
+                               UnwrapLeft.EmitCheck (ec);
+                       }
 
-                       // value & null, value | null
-                       if (right_unwrap != null) {
-                               right_unwrap.Emit (ec);
-                               ec.Emit (OpCodes.Brtrue_S, load_left);
+                       //
+                       // Don't emit HasValue check when left and right expressions are same
+                       //
+                       if (UnwrapRight != null && !Binary.Left.Equals (Binary.Right)) {
+                               UnwrapRight.EmitCheck (ec);
+                               if (UnwrapLeft != null) {
+                                       ec.Emit (OpCodes.And);
+                               }
                        }
 
-                       left_unwrap.EmitCheck (ec);
-                       ec.Emit (OpCodes.Brfalse_S, load_right);
+                       ec.Emit (OpCodes.Brfalse, is_null_label);
 
-                       // load left
-                       ec.MarkLabel (load_left);
+                       if (UserOperator != null) {
+                               var args = new Arguments (2);
+                               args.Add (new Argument (Left));
+                               args.Add (new Argument (Right));
 
-                       if (Oper == Operator.BitwiseAnd) {
-                               left_unwrap.Load (ec);
+                               var call = new CallEmitter ();
+                               call.EmitPredefined (ec, UserOperator, args);
                        } else {
-                               if (right_unwrap == null) {
-                                       right.Emit (ec);
-                                       if (right is EmptyConstantCast || right is EmptyCast)
-                                               ec.Emit (OpCodes.Newobj, NullableInfo.GetConstructor (type));
-                               } else {
-                                       right_unwrap.Load (ec);
-                                       right_unwrap = left_unwrap;
-                               }
+                               Binary.EmitOperator (ec, Left, Right);
                        }
+
+                       //
+                       // Wrap the result when the operator return type is nullable type
+                       //
+                       if (type.IsNullableType)
+                               ec.Emit (OpCodes.Newobj, NullableInfo.GetConstructor (type));
+
                        ec.Emit (OpCodes.Br_S, end_label);
+                       ec.MarkLabel (is_null_label);
 
-                       // load right
-                       ec.MarkLabel (load_right);
-                       if (right_unwrap == null) {
-                               if (Oper == Operator.BitwiseAnd) {
-                                       right.Emit (ec);
-                                       if (right is EmptyConstantCast || right is EmptyCast)
-                                               ec.Emit (OpCodes.Newobj, NullableInfo.GetConstructor (type));
-                               } else {
-                                       left_unwrap.Load (ec);
-                               }
+                       if ((Binary.Oper & Binary.Operator.ComparisonMask) != 0) {
+                               ec.EmitInt (0);
                        } else {
-                               right_unwrap.Load (ec);
+                               LiftedNull.Create (type, loc).Emit (ec);
                        }
 
                        ec.MarkLabel (end_label);
                }
 
-               //
-               // Emits optimized equality or inequality operator when possible
-               //
-               void EmitEquality (EmitContext ec)
+               void EmitBitwiseBoolean (EmitContext ec)
                {
+                       Label load_left = ec.DefineLabel ();
+                       Label load_right = ec.DefineLabel ();
+                       Label end_label = ec.DefineLabel ();
+                       Label is_null_label = ec.DefineLabel ();
+
+                       bool or = Binary.Oper == Binary.Operator.BitwiseOr;
+
                        //
-                       // Either left or right is null
+                       // Both operands are bool? types
                        //
-                       if (left_unwrap != null && (IsRightNullLifted || right.IsNull)) {
-                               left_unwrap.EmitCheck (ec);
-                               if (Oper == Binary.Operator.Equality) {
-                                       ec.Emit (OpCodes.Ldc_I4_0);
-                                       ec.Emit (OpCodes.Ceq);
-                               }
-                               return;
-                       }
-
-                       if (right_unwrap != null && (IsLeftNullLifted || left.IsNull)) {
-                               right_unwrap.EmitCheck (ec);
-                               if (Oper == Binary.Operator.Equality) {
-                                       ec.Emit (OpCodes.Ldc_I4_0);
-                                       ec.Emit (OpCodes.Ceq);
+                       if (UnwrapLeft != null && UnwrapRight != null) {
+                               if (ec.HasSet (BuilderContext.Options.AsyncBody) && Binary.Right.ContainsEmitWithAwait ()) {
+                                       Left = Left.EmitToField (ec);
+                                       Right = Right.EmitToField (ec);
                                }
-                               return;
-                       }
 
-                       Label dissimilar_label = ec.DefineLabel ();
-                       Label end_label = ec.DefineLabel ();
+                               Left.Emit (ec);
+                               ec.Emit (OpCodes.Brtrue_S, load_right);
 
-                       if (user_operator != null) {
-                               user_operator.Emit (ec);
-                               ec.Emit (Oper == Operator.Equality ? OpCodes.Brfalse_S : OpCodes.Brtrue_S, dissimilar_label);
-                       } else {
-                               left.Emit (ec);
-                               right.Emit (ec);
-
-                               ec.Emit (OpCodes.Bne_Un_S, dissimilar_label);
-                       }
-
-                       if (left_unwrap != null)
-                               left_unwrap.EmitCheck (ec);
+                               Right.Emit (ec);
+                               ec.Emit (OpCodes.Brtrue_S, load_left);
 
-                       if (right_unwrap != null)
-                               right_unwrap.EmitCheck (ec);
+                               UnwrapLeft.EmitCheck (ec);
+                               ec.Emit (OpCodes.Brfalse_S, load_right);
 
-                       if (left_unwrap != null && right_unwrap != null) {
-                               if (Oper == Operator.Inequality)
-                                       ec.Emit (OpCodes.Xor);
+                               // load left
+                               ec.MarkLabel (load_left);
+                               if (or)
+                                       UnwrapRight.Load (ec);
                                else
-                                       ec.Emit (OpCodes.Ceq);
-                       } else {
-                               if (Oper == Operator.Inequality) {
-                                       ec.Emit (OpCodes.Ldc_I4_0);
-                                       ec.Emit (OpCodes.Ceq);
-                               }
-                       }
+                                       UnwrapLeft.Load (ec);
 
-                       ec.Emit (OpCodes.Br_S, end_label);
+                               ec.Emit (OpCodes.Br_S, end_label);
 
-                       ec.MarkLabel (dissimilar_label);
-                       if (Oper == Operator.Inequality)
-                               ec.Emit (OpCodes.Ldc_I4_1);
-                       else
-                               ec.Emit (OpCodes.Ldc_I4_0);
+                               // load right
+                               ec.MarkLabel (load_right);
+                               if (or)
+                                       UnwrapLeft.Load (ec);
+                               else
+                                       UnwrapRight.Load (ec);
 
-                       ec.MarkLabel (end_label);
-               }
-               
-               public override void EmitBranchable (EmitContext ec, Label target, bool onTrue)
-               {
-                       Emit (ec);
-                       ec.Emit (onTrue ? OpCodes.Brtrue : OpCodes.Brfalse, target);
-               }                       
+                               ec.MarkLabel (end_label);
+                               return;
+                       }
 
-               public override void Emit (EmitContext ec)
-               {
                        //
-                       // Optimize same expression operation
+                       // Faster version when one operand is bool
                        //
-                       if (right_unwrap != null && right.Equals (left))
-                               right_unwrap = left_unwrap;
+                       if (UnwrapLeft == null) {
+                               //
+                               // (bool, bool?)
+                               //
+                               // Optimizes remaining (false & bool?), (true | bool?) which are not easy to handle
+                               // in binary expression reduction
+                               //
+                               var c = Left as BoolConstant;
+                               if (c != null) {
+                                       // Keep evaluation order
+                                       UnwrapRight.Store (ec);
+
+                                       ec.EmitInt (or ? 1 : 0);
+                                       ec.Emit (OpCodes.Newobj, NullableInfo.GetConstructor (type));
+                               } else if (Left.IsNull) {
+                                       UnwrapRight.Emit (ec);
+                                       ec.Emit (or ? OpCodes.Brfalse_S : OpCodes.Brtrue_S, is_null_label);
+
+                                       UnwrapRight.Load (ec);
+                                       ec.Emit (OpCodes.Br_S, end_label);
+
+                                       ec.MarkLabel (is_null_label);
+                                       LiftedNull.Create (type, loc).Emit (ec);
+                               } else {
+                                       Left.Emit (ec);
+                                       ec.Emit (or ? OpCodes.Brfalse_S : OpCodes.Brtrue_S, load_right);
 
-                       if (user_operator == null && IsBitwiseBoolean) {
-                               EmitBitwiseBoolean (ec);
-                               return;
-                       }
+                                       ec.EmitInt (or ? 1 : 0);
+                                       ec.Emit (OpCodes.Newobj, NullableInfo.GetConstructor (type));
 
-                       if ((Oper & Operator.EqualityMask) != 0) {
-                               EmitEquality (ec);
-                               return;
-                       }
+                                       ec.Emit (OpCodes.Br_S, end_label);
 
-                       Label is_null_label = ec.DefineLabel ();
-                       Label end_label = ec.DefineLabel ();
-
-                       if (left_unwrap != null) {
-                               left_unwrap.EmitCheck (ec);
-                               ec.Emit (OpCodes.Brfalse, is_null_label);
-                       }
+                                       ec.MarkLabel (load_right);
+                                       UnwrapRight.Original.Emit (ec);
+                               }
+                       } else {
+                               //
+                               // (bool?, bool)
+                               //
+                               // Keep left-right evaluation order
+                               UnwrapLeft.Store (ec);
 
-                       //
-                       // Don't emit HasValue check when left and right expressions are same
-                       //
-                       if (right_unwrap != null && !left.Equals (right)) {
-                               right_unwrap.EmitCheck (ec);
-                               ec.Emit (OpCodes.Brfalse, is_null_label);
-                       }
+                               //
+                               // Optimizes remaining (bool? & false), (bool? | true) which are not easy to handle
+                               // in binary expression reduction
+                               //
+                               var c = Right as BoolConstant;
+                               if (c != null) {
+                                       ec.EmitInt (or ? 1 : 0);
+                                       ec.Emit (OpCodes.Newobj, NullableInfo.GetConstructor (type));
+                               } else if (Right.IsNull) {
+                                       UnwrapLeft.Emit (ec);
+                                       ec.Emit (or ? OpCodes.Brfalse_S : OpCodes.Brtrue_S, is_null_label);
+
+                                       UnwrapLeft.Load (ec);
+                                       ec.Emit (OpCodes.Br_S, end_label);
+
+                                       ec.MarkLabel (is_null_label);
+                                       LiftedNull.Create (type, loc).Emit (ec);
+                               } else {
+                                       Right.Emit (ec);
+                                       ec.Emit (or ? OpCodes.Brfalse_S : OpCodes.Brtrue_S, load_right);
 
-                       EmitOperator (ec, left.Type);
+                                       ec.EmitInt (or ? 1 : 0);
+                                       ec.Emit (OpCodes.Newobj, NullableInfo.GetConstructor (type));
 
-                       if (wrap_ctor != null)
-                               ec.Emit (OpCodes.Newobj, wrap_ctor);
+                                       ec.Emit (OpCodes.Br_S, end_label);
 
-                       ec.Emit (OpCodes.Br_S, end_label);
-                       ec.MarkLabel (is_null_label);
+                                       ec.MarkLabel (load_right);
 
-                       if ((Oper & Operator.ComparisonMask) != 0) {
-                               ec.Emit (OpCodes.Ldc_I4_0);
-                       } else {
-                               LiftedNull.Create (type, loc).Emit (ec);
+                                       UnwrapLeft.Load (ec);
+                               }
                        }
 
                        ec.MarkLabel (end_label);
-               }
+               }
 
-               protected override void EmitOperator (EmitContext ec, TypeSpec l)
+               //
+               // Emits optimized equality or inequality operator when possible
+               //
+               void EmitEquality (EmitContext ec)
                {
-                       if (user_operator != null) {
-                               user_operator.Emit (ec);
+                       //
+                       // Either left or right is null
+                       // 
+                       if (UnwrapLeft != null && Binary.Right.IsNull) { // TODO: Optimize for EmitBranchable
+                               //
+                               // left.HasValue == false 
+                               //
+                               UnwrapLeft.EmitCheck (ec);
+                               if (Binary.Oper == Binary.Operator.Equality) {
+                                       ec.EmitInt (0);
+                                       ec.Emit (OpCodes.Ceq);
+                               }
                                return;
                        }
 
-                       if (l.IsNullableType)
-                               l = TypeManager.GetTypeArguments (l) [0];
+                       if (UnwrapRight != null && Binary.Left.IsNull) {
+                               //
+                               // right.HasValue == false 
+                               //
+                               UnwrapRight.EmitCheck (ec);
+                               if (Binary.Oper == Binary.Operator.Equality) {
+                                       ec.EmitInt (0);
+                                       ec.Emit (OpCodes.Ceq);
+                               }
+                               return;
+                       }
 
-                       base.EmitOperator (ec, l);
-               }
+                       Label dissimilar_label = ec.DefineLabel ();
+                       Label end_label = ec.DefineLabel ();
 
-               Expression LiftResult (ResolveContext ec, Expression res_expr)
-               {
-                       TypeExpr lifted_type;
+                       if (UserOperator != null) {
+                               var left = Left;
 
-                       //
-                       // Avoid double conversion
-                       //
-                       if (left_unwrap == null || IsLeftNullLifted || left_unwrap.Type != left.Type || (left_unwrap != null && IsRightNullLifted)) {
-                               lifted_type = new NullableType (left.Type, loc);
-                               lifted_type = lifted_type.ResolveAsTypeTerminal (ec, false);
-                               if (lifted_type == null)
-                                       return null;
+                               if (UnwrapLeft != null) {
+                                       UnwrapLeft.EmitCheck (ec);
+                               } else {
+                                       // Keep evaluation order same
+                                       if (!(Left is VariableReference)) {
+                                               Left.Emit (ec);
+                                               var lt = new LocalTemporary (Left.Type);
+                                               lt.Store (ec);
+                                               left = lt;
+                                       }
+                               }
 
-                               if (left is UserCast || left is TypeCast)
-                                       left.Type = lifted_type.Type;
-                               else
-                                       left = EmptyCast.Create (left, lifted_type.Type);
-                       }
+                               if (UnwrapRight != null) {
+                                       UnwrapRight.EmitCheck (ec);
 
-                       if (left != right && (right_unwrap == null || IsRightNullLifted || right_unwrap.Type != right.Type || (right_unwrap != null && IsLeftNullLifted))) {
-                               lifted_type = new NullableType (right.Type, loc);
-                               lifted_type = lifted_type.ResolveAsTypeTerminal (ec, false);
-                               if (lifted_type == null)
-                                       return null;
+                                       if (UnwrapLeft != null) {
+                                               ec.Emit (OpCodes.Bne_Un, dissimilar_label);
 
-                               var r = right;
-                               if (r is ReducedExpression)
-                                       r = ((ReducedExpression) r).OriginalExpression;
+                                               Label compare_label = ec.DefineLabel ();
+                                               UnwrapLeft.EmitCheck (ec);
+                                               ec.Emit (OpCodes.Brtrue, compare_label);
 
-                               if (r is UserCast || r is TypeCast)
-                                       r.Type = lifted_type.Type;
-                               else
-                                       right = EmptyCast.Create (right, lifted_type.Type);
-                       }
+                                               if (Binary.Oper == Binary.Operator.Equality)
+                                                       ec.EmitInt (1);
+                                               else
+                                                       ec.EmitInt (0);
 
-                       if ((Oper & Operator.ComparisonMask) == 0) {
-                               lifted_type = new NullableType (res_expr.Type, loc);
-                               lifted_type = lifted_type.ResolveAsTypeTerminal (ec, false);
-                               if (lifted_type == null)
-                                       return null;
+                                               ec.Emit (OpCodes.Br, end_label);
 
-                               wrap_ctor = NullableInfo.GetConstructor (lifted_type.Type);
-                               type = res_expr.Type = lifted_type.Type;
-                       }
+                                               ec.MarkLabel (compare_label);
+                                       } else {
+                                               ec.Emit (OpCodes.Brfalse, dissimilar_label);
+                                       }
+                               } else {
+                                       ec.Emit (OpCodes.Brfalse, dissimilar_label);
+                               }
 
-                       if (IsLeftNullLifted) {
-                               left = LiftedNull.Create (right.Type, left.Location);
+                               var args = new Arguments (2);
+                               args.Add (new Argument (left));
+                               args.Add (new Argument (Right));
 
-                               //
-                               // Special case for bool?, the result depends on both null right side and left side value
-                               //
-                               if ((Oper == Operator.BitwiseAnd || Oper == Operator.BitwiseOr) && NullableInfo.GetUnderlyingType (type).BuildinType == BuildinTypeSpec.Type.Bool) {
-                                       return res_expr;
+                               var call = new CallEmitter ();
+                               call.EmitPredefined (ec, UserOperator, args);
+                       } else {
+                               if (ec.HasSet (BuilderContext.Options.AsyncBody) && Binary.Right.ContainsEmitWithAwait ()) {
+                                       Left = Left.EmitToField (ec);
+                                       Right = Right.EmitToField (ec);
                                }
 
-                               if ((Oper & (Operator.ArithmeticMask | Operator.ShiftMask | Operator.BitwiseMask)) != 0)
-                                       return LiftedNull.CreateFromExpression (ec, res_expr);
-
                                //
-                               // Value types and null comparison
+                               // Emit underlying value comparison first.
                                //
-                               if (right_unwrap == null || (Oper & Operator.RelationalMask) != 0)
-                                       return CreateNullConstant (ec, right_orig);
-                       }
-
-                       if (IsRightNullLifted) {
-                               right = LiftedNull.Create (left.Type, right.Location);
-
+                               // For this code: int? a = 1; bool b = a == 1;
                                //
-                               // Special case for bool?, the result depends on both null right side and left side value
+                               // We emit something similar to this. Expressions with side effects have local
+                               // variable created by Unwrap expression
                                //
-                               if ((Oper == Operator.BitwiseAnd || Oper == Operator.BitwiseOr) && NullableInfo.GetUnderlyingType (type).BuildinType == BuildinTypeSpec.Type.Bool) {
-                                       return res_expr;
-                               }
+                               //      left.GetValueOrDefault ()
+                               //      right
+                               //      bne.un.s   dissimilar_label
+                               //  left.HasValue
+                               //      br.s       end_label
+                               // dissimilar_label:
+                               //      ldc.i4.0
+                               // end_label:
+                               //
+
+                               Left.Emit (ec);
+                               Right.Emit (ec);
 
-                               if ((Oper & (Operator.ArithmeticMask | Operator.ShiftMask | Operator.BitwiseMask)) != 0)
-                                       return LiftedNull.CreateFromExpression (ec, res_expr);
+                               ec.Emit (OpCodes.Bne_Un_S, dissimilar_label);
 
                                //
-                               // Value types and null comparison
+                               // Check both left and right expressions for Unwrap call in which
+                               // case we need to run get_HasValue() check because the type is
+                               // nullable and could have null value
                                //
-                               if (left_unwrap == null || (Oper & Operator.RelationalMask) != 0)
-                                       return CreateNullConstant (ec, left_orig);
-                       }
+                               if (UnwrapLeft != null)
+                                       UnwrapLeft.EmitCheck (ec);
 
-                       return res_expr;
-               }
+                               if (UnwrapRight != null)
+                                       UnwrapRight.EmitCheck (ec);
 
-               protected override Expression ResolveOperatorPredefined (ResolveContext ec, Binary.PredefinedOperator [] operators, bool primitives_only, TypeSpec enum_type)
-               {
-                       Expression e = base.ResolveOperatorPredefined (ec, operators, primitives_only, enum_type);
+                               if (UnwrapLeft != null && UnwrapRight != null) {
+                                       if (Binary.Oper == Binary.Operator.Inequality)
+                                               ec.Emit (OpCodes.Xor);
+                                       else
+                                               ec.Emit (OpCodes.Ceq);
+                               } else {
+                                       if (Binary.Oper == Binary.Operator.Inequality) {
+                                               ec.EmitInt (0);
+                                               ec.Emit (OpCodes.Ceq);
+                                       }
+                               }
+                       }
 
-                       if (e == this || enum_type != null)
-                               return LiftResult (ec, e);
+                       ec.Emit (OpCodes.Br_S, end_label);
 
-                       //
-                       // 7.9.9 Equality operators and null
-                       //
-                       // The == and != operators permit one operand to be a value of a nullable type and
-                       // the other to be the null literal, even if no predefined or user-defined operator
-                       // (in unlifted or lifted form) exists for the operation.
-                       //
-                       if (e == null && (Oper & Operator.EqualityMask) != 0) {
-                               if ((IsLeftNullLifted && right_unwrap != null) || (IsRightNullLifted && left_unwrap != null))
-                                       return LiftResult (ec, this);
-                       }
+                       ec.MarkLabel (dissimilar_label);
+                       if (Binary.Oper == Binary.Operator.Inequality)
+                               ec.EmitInt (1);
+                       else
+                               ec.EmitInt (0);
 
-                       return e;
+                       ec.MarkLabel (end_label);
                }
 
-               protected override Expression ResolveUserOperator (ResolveContext ec, Expression left, Expression right)
+               public override SLE.Expression MakeExpression (BuilderContext ctx)
                {
-                       //
-                       // Try original types first for exact match without unwrapping
-                       //
-                       Expression expr = base.ResolveUserOperator (ec, left_orig, right_orig);
-                       if (expr != null)
-                               return expr;
-
-                       State orig_state = state;
+                       Console.WriteLine (":{0} x {1}", Left.GetType (), Right.GetType ());
 
-                       //
-                       // One side is a nullable type, try to match underlying types
-                       //
-                       if (left_unwrap != null || right_unwrap != null || (state & (State.RightNullLifted | State.LeftNullLifted)) != 0) {
-                               expr = base.ResolveUserOperator (ec, left, right);
-                       }
-
-                       if (expr == null)
-                               return null;
-
-                       //
-                       // Lift the result in the case it can be null and predefined or user operator
-                       // result type is of a value type
-                       //
-                       if (!TypeManager.IsValueType (expr.Type))
-                               return null;
-
-                       if (state != orig_state)
-                               return expr;
-
-                       expr = LiftResult (ec, expr);
-                       if (expr is Constant)
-                               return expr;
-
-                       type = expr.Type;
-                       user_operator = expr;
-                       return this;
+                       return Binary.MakeExpression (ctx, Left, Right);
                }
        }
 
@@ -1019,11 +1021,23 @@ namespace Mono.CSharp.Nullable
                Expression left, right;
                Unwrap unwrap;
 
-               public NullCoalescingOperator (Expression left, Expression right, Location loc)
+               public NullCoalescingOperator (Expression left, Expression right)
                {
                        this.left = left;
                        this.right = right;
-                       this.loc = loc;
+                       this.loc = left.Location;
+               }
+
+               public Expression LeftExpression {
+                       get {
+                               return left;
+                       }
+               }
+
+               public Expression RightExpression {
+                       get {
+                               return right;
+                       }
                }
                
                public override Expression CreateExpressionTree (ResolveContext ec)
@@ -1081,7 +1095,7 @@ namespace Mono.CSharp.Nullable
                                        //
                                        // If right is a dynamic expression, the result type is dynamic
                                        //
-                                       if (right.Type.BuildinType == BuildinTypeSpec.Type.Dynamic) {
+                                       if (right.Type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
                                                type = right.Type;
 
                                                // Need to box underlying value type
@@ -1093,12 +1107,12 @@ namespace Mono.CSharp.Nullable
                                        type = ltype;
                                        return this;
                                }
-                       } else if (TypeManager.IsReferenceType (ltype)) {
+                       } else if (TypeSpec.IsReferenceType (ltype)) {
                                if (Convert.ImplicitConversionExists (ec, right, ltype)) {
                                        //
                                        // If right is a dynamic expression, the result type is dynamic
                                        //
-                                       if (right.Type.BuildinType == BuildinTypeSpec.Type.Dynamic) {
+                                       if (right.Type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
                                                type = right.Type;
                                                return this;
                                        }
@@ -1147,6 +1161,14 @@ namespace Mono.CSharp.Nullable
                        return this;
                }
 
+               public override bool ContainsEmitWithAwait ()
+               {
+                       if (unwrap != null)
+                               return unwrap.ContainsEmitWithAwait () || right.ContainsEmitWithAwait ();
+
+                       return left.ContainsEmitWithAwait () || right.ContainsEmitWithAwait ();
+               }
+
                protected override Expression DoResolve (ResolveContext ec)
                {
                        left = left.Resolve (ec);
@@ -1208,77 +1230,65 @@ namespace Mono.CSharp.Nullable
                        target.left = left.Clone (clonectx);
                        target.right = right.Clone (clonectx);
                }
-       }
-
-       public class LiftedUnaryMutator : ExpressionStatement
-       {
-               public readonly UnaryMutator.Mode Mode;
-               Expression expr;
-               UnaryMutator underlying;
-               Unwrap unwrap;
-
-               public LiftedUnaryMutator (UnaryMutator.Mode mode, Expression expr, Location loc)
+               
+               public override object Accept (StructuralVisitor visitor)
                {
-                       this.expr = expr;
-                       this.Mode = mode;
-                       this.loc = loc;
+                       return visitor.Visit (this);
                }
+       }
 
-               public override Expression CreateExpressionTree (ResolveContext ec)
+       class LiftedUnaryMutator : UnaryMutator
+       {
+               public LiftedUnaryMutator (Mode mode, Expression expr, Location loc)
+                       : base (mode, expr, loc)
                {
-                       return new SimpleAssign (this, this).CreateExpressionTree (ec);
                }
 
                protected override Expression DoResolve (ResolveContext ec)
                {
-                       expr = expr.Resolve (ec);
-                       if (expr == null)
-                               return null;
+                       var orig_expr = expr;
 
-                       unwrap = Unwrap.Create (expr, false);
-                       if (unwrap == null)
-                               return null;
+                       expr = Unwrap.Create (expr);
 
-                       underlying = (UnaryMutator) new UnaryMutator (Mode, unwrap, loc).Resolve (ec);
-                       if (underlying == null)
-                               return null;
+                       var res = base.DoResolveOperation (ec);
 
-
-                       eclass = ExprClass.Value;
+                       expr = orig_expr;
                        type = expr.Type;
-                       return this;
+
+                       return res;
                }
 
-               void DoEmit (EmitContext ec, bool is_expr)
+               protected override void EmitOperation (EmitContext ec)
                {
                        Label is_null_label = ec.DefineLabel ();
                        Label end_label = ec.DefineLabel ();
 
-                       unwrap.EmitCheck (ec);
+                       LocalTemporary lt = new LocalTemporary (type);
+
+                       // Value is on the stack
+                       lt.Store (ec);
+
+                       var call = new CallEmitter ();
+                       call.InstanceExpression = lt;
+                       call.EmitPredefined (ec, NullableInfo.GetHasValue (expr.Type), null);
+
                        ec.Emit (OpCodes.Brfalse, is_null_label);
 
-                       if (is_expr) {
-                               underlying.Emit (ec);
-                               ec.Emit (OpCodes.Br_S, end_label);
-                       } else {
-                               underlying.EmitStatement (ec);
-                       }
+                       call = new CallEmitter ();
+                       call.InstanceExpression = lt;
+                       call.EmitPredefined (ec, NullableInfo.GetGetValueOrDefault (expr.Type), null);
 
-                       ec.MarkLabel (is_null_label);
-                       if (is_expr)
-                               LiftedNull.Create (type, loc).Emit (ec);
+                       lt.Release (ec);
 
-                       ec.MarkLabel (end_label);
-               }
+                       base.EmitOperation (ec);
 
-               public override void Emit (EmitContext ec)
-               {
-                       DoEmit (ec, true);
-               }
+                       ec.Emit (OpCodes.Newobj, NullableInfo.GetConstructor (type));
+                       ec.Emit (OpCodes.Br_S, end_label);
 
-               public override void EmitStatement (EmitContext ec)
-               {
-                       DoEmit (ec, false);
+                       ec.MarkLabel (is_null_label);
+                       LiftedNull.Create (type, loc).Emit (ec);
+
+                       ec.MarkLabel (end_label);
                }
        }
 }