Browse Source

2002-07-10 Miguel de Icaza <[email protected]>

	* expression.cs (MemberAccess.ResolveMemberAccess): Since we can
	not catch the Error_ObjectRefRequired in SimpleName (as it is
	possible to have a class/instance variable name that later gets
	deambiguated), we have to check this here.

svn path=/trunk/mcs/; revision=5690
Miguel de Icaza 23 years ago
parent
commit
2f3d823bbc
3 changed files with 34 additions and 10 deletions
  1. 7 0
      mcs/mcs/ChangeLog
  2. 6 6
      mcs/mcs/ecore.cs
  3. 21 4
      mcs/mcs/expression.cs

+ 7 - 0
mcs/mcs/ChangeLog

@@ -1,3 +1,10 @@
+2002-07-10  Miguel de Icaza  <[email protected]>
+
+	* expression.cs (MemberAccess.ResolveMemberAccess): Since we can
+	not catch the Error_ObjectRefRequired in SimpleName (as it is
+	possible to have a class/instance variable name that later gets
+	deambiguated), we have to check this here. 	
+
 2002-07-10  Ravi Pratap  <[email protected]>
 
 	* class.cs (TypeContainer.GetFieldFromEvent): Move away from here,

+ 6 - 6
mcs/mcs/ecore.cs

@@ -3085,7 +3085,7 @@ namespace Mono.CSharp {
 			Location = l;
 		}
 
-		public static void Error120 (Location l, string name)
+		public static void Error_ObjectRefRequired (Location l, string name)
 		{
 			Report.Error (
 				120, l,
@@ -3103,25 +3103,25 @@ namespace Mono.CSharp {
 				FieldInfo fi = ((FieldExpr) e).FieldInfo;
 				
 				if (!fi.IsStatic){
-					Error120 (Location, Name);
+					Error_ObjectRefRequired (Location, Name);
 					return null;
 				}
 			} else if (e is MethodGroupExpr){
 				MethodGroupExpr mg = (MethodGroupExpr) e;
 
 				if (!mg.RemoveInstanceMethods ()){
-					Error120 (Location, mg.Methods [0].Name);
+					Error_ObjectRefRequired (Location, mg.Methods [0].Name);
 					return null;
 				}
 				return e;
 			} else if (e is PropertyExpr){
 				if (!((PropertyExpr) e).IsStatic){
-					Error120 (Location, Name);
+					Error_ObjectRefRequired (Location, Name);
 					return null;
 				}
 			} else if (e is EventExpr) {
 				if (!((EventExpr) e).IsStatic) {
-					Error120 (Location, Name);
+					Error_ObjectRefRequired (Location, Name);
 					return null;
 				}
 			}
@@ -3267,7 +3267,7 @@ namespace Mono.CSharp {
 				
 				if (ec.IsStatic){
 					if (!allow_static && !fi.IsStatic){
-						Error120 (Location, Name);
+						Error_ObjectRefRequired (Location, Name);
 						return null;
 					}
 				} else {

+ 21 - 4
mcs/mcs/expression.cs

@@ -5067,7 +5067,7 @@ namespace Mono.CSharp {
 				//
 				if (left is TypeExpr){
 					if (!mg.RemoveInstanceMethods ()){
-						SimpleName.Error120 (loc, mg.Methods [0].Name); 
+						SimpleName.Error_ObjectRefRequired (loc, mg.Methods [0].Name); 
 						return null;
 					}
 
@@ -5093,7 +5093,7 @@ namespace Mono.CSharp {
 				if (!mg.RemoveStaticMethods ()){
 					if (IdenticalNameAndTypeName (ec, left_original, loc)){
 						if (!mg.RemoveInstanceMethods ()){
-							SimpleName.Error120 (loc, mg.Methods [0].Name);
+							SimpleName.Error_ObjectRefRequired (loc, mg.Methods [0].Name);
 							return null;
 						}
 						return member_lookup;
@@ -5181,6 +5181,23 @@ namespace Mono.CSharp {
 						error176 (loc, fe.FieldInfo.Name);
 						return null;
 					}
+
+					//
+					// Since we can not check for instance objects in SimpleName,
+					// becaue of the rule that allows types and variables to share
+					// the name (as long as they can be de-ambiguated later, see 
+					// IdenticalNameAndTypeName), we have to check whether left 
+					// is an instance variable in a static context
+					//
+
+					if (ec.IsStatic && left is FieldExpr){
+						FieldExpr fexp = (FieldExpr) left;
+
+						if (!fexp.FieldInfo.IsStatic){
+							SimpleName.Error_ObjectRefRequired (loc, fexp.FieldInfo.Name);
+							return null;
+						}
+					}
 					fe.InstanceExpression = left;
 
 					return fe;
@@ -5192,7 +5209,7 @@ namespace Mono.CSharp {
 
 				if (left is TypeExpr){
 					if (!pe.IsStatic){
-						SimpleName.Error120 (loc, pe.PropertyInfo.Name);
+						SimpleName.Error_ObjectRefRequired (loc, pe.PropertyInfo.Name);
 						return null;
 					}
 					return pe;
@@ -5246,7 +5263,7 @@ namespace Mono.CSharp {
 
 				if (left is TypeExpr) {
 					if (!ee.IsStatic) {
-						SimpleName.Error120 (loc, ee.EventInfo.Name);
+						SimpleName.Error_ObjectRefRequired (loc, ee.EventInfo.Name);
 						return null;
 					}