Author: martin
Date: 2005-04-20 10:25:17 -0400 (Wed, 20 Apr 2005)
New Revision: 43338
Modified:
trunk/mcs/gmcs/ChangeLog
trunk/mcs/gmcs/codegen.cs
trunk/mcs/gmcs/ecore.cs
trunk/mcs/gmcs/expression.cs
Log:
**** Merged r43314 from MCS ****
Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog 2005-04-20 14:25:00 UTC (rev 43337)
+++ trunk/mcs/gmcs/ChangeLog 2005-04-20 14:25:17 UTC (rev 43338)
@@ -1,3 +1,12 @@
+2005-04-20 Marek Safar <[EMAIL PROTECTED]>
+
+ * codegen.cs (InRefOutArgumentResolving): New field.
+
+ * ecore.cs (FieldExpr.DoResolve): Check for assigning to readonly
+ fields outside contructor.
+
+ * expression.cs (Argument.Resolve): Set InRefOutArgumentResolving.
+
2005-04-19 Miguel de Icaza <[EMAIL PROTECTED]>
* anonymous.cs (CaptureContext.EmitParameterInstance): The
Modified: trunk/mcs/gmcs/codegen.cs
===================================================================
--- trunk/mcs/gmcs/codegen.cs 2005-04-20 14:25:00 UTC (rev 43337)
+++ trunk/mcs/gmcs/codegen.cs 2005-04-20 14:25:17 UTC (rev 43338)
@@ -383,6 +383,8 @@
/// </summary>
public bool InFixedInitializer;
+ public bool InRefOutArgumentResolving;
+
public bool InCatch;
public bool InFinally;
Modified: trunk/mcs/gmcs/ecore.cs
===================================================================
--- trunk/mcs/gmcs/ecore.cs 2005-04-20 14:25:00 UTC (rev 43337)
+++ trunk/mcs/gmcs/ecore.cs 2005-04-20 14:25:17 UTC (rev 43338)
@@ -3050,6 +3050,25 @@
override public Expression DoResolve (EmitContext ec)
{
+ if (ec.InRefOutArgumentResolving &&
FieldInfo.IsInitOnly && !ec.IsConstructor && FieldInfo.FieldType.IsValueType) {
+ if (FieldInfo.FieldType is TypeBuilder) {
+ if (FieldInfo.IsStatic)
+ Report.Error (1651, loc,
"Members of readonly static field '{0}.{1}' cannot be passed ref or out (except
in a constructor)",
+ TypeManager.CSharpName
(DeclaringType), Name);
+ else
+ Report.Error (1649, loc,
"Members of readonly field '{0}.{1}' cannot be passed ref or out (except in a
constructor)",
+ TypeManager.CSharpName
(DeclaringType), Name);
+ } else {
+ if (FieldInfo.IsStatic)
+ Report.Error (199, loc, "A
static readonly field '{0}' cannot be passed ref or out (except in a static
constructor)",
+ Name);
+ else
+ Report.Error (192, loc, "A
readonly field '{0}' cannot be passed ref or out (except in a constructor)",
+ Name);
+ }
+ return null;
+ }
+
if (!FieldInfo.IsStatic){
if (InstanceExpression == null){
//
Modified: trunk/mcs/gmcs/expression.cs
===================================================================
--- trunk/mcs/gmcs/expression.cs 2005-04-20 14:25:00 UTC (rev 43337)
+++ trunk/mcs/gmcs/expression.cs 2005-04-20 14:25:17 UTC (rev 43338)
@@ -4242,25 +4242,20 @@
public bool Resolve (EmitContext ec, Location loc)
{
if (ArgType == AType.Ref) {
+ ec.InRefOutArgumentResolving = true;
Expr = Expr.Resolve (ec);
+ ec.InRefOutArgumentResolving = false;
if (Expr == null)
return false;
- if (!ec.IsConstructor) {
- FieldExpr fe = Expr as FieldExpr;
- if (fe != null &&
fe.FieldInfo.IsInitOnly) {
- if (fe.FieldInfo.IsStatic)
- Report.Error (199, loc,
"A static readonly field cannot be passed ref or out (except in a static
constructor)");
- else
- Report.Error (192, loc,
"A readonly field cannot be passed ref or out (except in a constructor)");
- return false;
- }
- }
Expr = Expr.DoResolveLValue (ec, Expr);
if (Expr == null)
Error_LValueRequired (loc);
} else if (ArgType == AType.Out) {
+ ec.InRefOutArgumentResolving = true;
Expr = Expr.DoResolveLValue (ec,
EmptyExpression.Null);
+ ec.InRefOutArgumentResolving = false;
+
if (Expr == null)
Error_LValueRequired (loc);
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches