Fixed string null constant conversion to object constant
[mono.git] / mcs / mcs / assign.cs
index f72d48195cee10d2787928d661b6e81a28c9a48c..61cb8e239275e94c9375e11e2958f804567b6f8d 100644 (file)
@@ -310,6 +310,12 @@ namespace Mono.CSharp {
                        }
                }
 
+               public override Location StartLocation {
+                       get {
+                               return target.StartLocation;
+                       }
+               }
+
                public override bool ContainsEmitWithAwait ()
                {
                        return target.ContainsEmitWithAwait () || source.ContainsEmitWithAwait ();
@@ -343,7 +349,7 @@ namespace Mono.CSharp {
                        type = target_type;
 
                        if (!(target is IAssignMethod)) {
-                               Error_ValueAssignment (ec, source);
+                               target.Error_ValueAssignment (ec, source);
                                return null;
                        }
 
@@ -536,16 +542,22 @@ namespace Mono.CSharp {
                // Keep resolved value because field initializers have their own rules
                //
                ExpressionStatement resolved;
-               IMemberContext mc;
+               FieldBase mc;
 
-               public FieldInitializer (FieldSpec spec, Expression expression, IMemberContext mc)
-                       : base (new FieldExpr (spec, expression.Location), expression, expression.Location)
+               public FieldInitializer (FieldBase mc, Expression expression, Location loc)
+                       : base (new FieldExpr (mc.Spec, expression.Location), expression, loc)
                {
                        this.mc = mc;
-                       if (!spec.IsStatic)
+                       if (!mc.IsStatic)
                                ((FieldExpr)target).InstanceExpression = new CompilerGeneratedThis (mc.CurrentType, expression.Location);
                }
 
+               public override Location StartLocation {
+                       get {
+                               return loc;
+                       }
+               }
+
                protected override Expression DoResolve (ResolveContext ec)
                {
                        // Field initializer can be resolved (fail) many times
@@ -567,10 +579,10 @@ namespace Mono.CSharp {
 
                        //
                        // Emit sequence symbol info even if we are in compiler generated
-                       // block to allow debugging filed initializers when constructor is
+                       // block to allow debugging field initializers when constructor is
                        // compiler generated
                        //
-                       if (ec.HasSet (BuilderContext.Options.OmitDebugInfo)) {
+                       if (ec.HasSet (BuilderContext.Options.OmitDebugInfo) && ec.HasMethodSymbolBuilder) {
                                using (ec.With (BuilderContext.Options.OmitDebugInfo, false)) {
                                        ec.Mark (loc);
                                }
@@ -649,15 +661,15 @@ namespace Mono.CSharp {
                Expression right;
                Expression left;
 
-               public CompoundAssign (Binary.Operator op, Expression target, Expression source, Location loc)
-                       : base (target, source, loc)
+               public CompoundAssign (Binary.Operator op, Expression target, Expression source)
+                       : base (target, source, target.Location)
                {
                        right = source;
                        this.op = op;
                }
 
-               public CompoundAssign (Binary.Operator op, Expression target, Expression source, Expression left, Location loc)
-                       : this (op, target, source, loc)
+               public CompoundAssign (Binary.Operator op, Expression target, Expression source, Expression left)
+                       : this (op, target, source)
                {
                        this.left = left;
                }
@@ -720,7 +732,7 @@ namespace Mono.CSharp {
                        if (left == null)
                                left = new TargetExpression (target);
 
-                       source = new Binary (op, left, right, true, loc);
+                       source = new Binary (op, left, right, true);
 
                        if (target is DynamicMemberAssignable) {
                                Arguments targs = ((DynamicMemberAssignable) target).Arguments;
@@ -792,8 +804,17 @@ namespace Mono.CSharp {
                        // Otherwise, if the selected operator is a predefined operator
                        //
                        Binary b = source as Binary;
-                       if (b == null && source is ReducedExpression)
-                               b = ((ReducedExpression) source).OriginalExpression as Binary;
+                       if (b == null) {
+                               if (source is ReducedExpression)
+                                       b = ((ReducedExpression) source).OriginalExpression as Binary;
+                               else if (source is Nullable.LiftedBinaryOperator) {
+                                       var po = ((Nullable.LiftedBinaryOperator) source);
+                                       if (po.UserOperator == null)
+                                               b = po.Binary;
+                               } else if (source is TypeCast) {
+                                       b = ((TypeCast) source).Child as Binary;
+                               }
+                       }
 
                        if (b != null) {
                                //
@@ -815,7 +836,7 @@ namespace Mono.CSharp {
                                return new SimpleAssign (target, new DynamicConversion (target_type, CSharpBinderFlags.ConvertExplicit, arg, loc), loc).Resolve (ec);
                        }
 
-                       right.Error_ValueCannotBeConverted (ec, loc, target_type, false);
+                       right.Error_ValueCannotBeConverted (ec, target_type, false);
                        return null;
                }