X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fgmcs%2Fassign.cs;h=b4b75fbfdfe91dad17e8acb2be42da73fefccfb4;hb=e7e6591153da6bdfefdd7f5e0a3ab2f4b06cfeac;hp=cf6008979fd5c562ebb66e05ee8f2702d1725635;hpb=699e59742843044f6efa1726b7cb64f19d909e64;p=mono.git diff --git a/mcs/gmcs/assign.cs b/mcs/gmcs/assign.cs old mode 100755 new mode 100644 index cf6008979fd..b4b75fbfdfe --- a/mcs/gmcs/assign.cs +++ b/mcs/gmcs/assign.cs @@ -3,9 +3,10 @@ // // Author: // Miguel de Icaza (miguel@ximian.com) -// Martin Baulig (martin@gnome.org) +// Martin Baulig (martin@ximian.com) // // (C) 2001, 2002, 2003 Ximian, Inc. +// (C) 2004 Novell, Inc // using System; using System.Reflection; @@ -312,8 +313,11 @@ namespace Mono.CSharp { source = embedded = ((Assign) source).GetEmbeddedAssign (loc); real_source = source = source.Resolve (ec); - if (source == null) + if (source == null) { + // Ensure that we don't propagate the error as spurious "uninitialized variable" errors. + target = target.ResolveLValue (ec, EmptyExpression.Null, Location); return null; + } // // This is used in an embedded assignment. @@ -344,11 +348,15 @@ namespace Mono.CSharp { if (embedded != null) source = (embedded.temp != null) ? embedded.temp : embedded.source; - target = target.ResolveLValue (ec, source); + target = target.ResolveLValue (ec, source, Location); if (target == null) return null; + if (source.Equals (target)) { + Report.Warning (1717, 3, loc, "Assignment made to same variable; did you mean to assign something else?"); + } + Type target_type = target.Type; Type source_type = real_source.Type; @@ -386,6 +394,21 @@ namespace Mono.CSharp { } } + FieldExpr field_exp = target as FieldExpr; + if (field_exp != null && field_exp.DeclaringType.IsValueType && !ec.IsConstructor && !ec.IsFieldInitializer) { + field_exp = field_exp.InstanceExpression as FieldExpr; + if (field_exp != null && field_exp.FieldInfo.IsInitOnly) { + if (field_exp.IsStatic) { + Report.Error (1650, loc, "Members of static readonly field '{0}' cannot be assigned to " + + "(except in a static constructor or a variable initializer)", TypeManager.GetFullNameSignature (field_exp.FieldInfo)); + } else { + Report.Error (1648, loc, "Members of readonly field '{0}' cannot be assigned to " + + "(except in a constructor or a variable initializer)", TypeManager.GetFullNameSignature (field_exp.FieldInfo)); + } + return null; + } + } + if (!(target is IAssignMethod) && (target.eclass != ExprClass.EventAccess)) { Report.Error (131, loc, "Left hand of an assignment must be a variable, " +