Jelajahi Sumber

2005-03-07 Duncan Mak <[email protected]>

	* codegen.cs (Save):  Catch UnauthorizedAccessException as
	well. Fixes bug #73454.

svn path=/trunk/mcs/; revision=41544
Duncan Mak 21 tahun lalu
induk
melakukan
b871d2d19d
5 mengubah file dengan 63 tambahan dan 12 penghapusan
  1. 5 0
      mcs/mcs/ChangeLog
  2. 3 0
      mcs/mcs/codegen.cs
  3. 13 6
      mcs/mcs/convert.cs
  4. 8 0
      mcs/mcs/cs-tokenizer.cs
  5. 34 6
      mcs/mcs/expression.cs

+ 5 - 0
mcs/mcs/ChangeLog

@@ -1,3 +1,8 @@
+2005-03-07  Duncan Mak  <[email protected]>
+
+	* codegen.cs (Save):  Catch UnauthorizedAccessException as
+	well. Fixes bug #73454.
+
 2005-03-07  Marek Safar  <[email protected]>
 
 	* cs-tokenizer.cs (xtoken): Add CS1035.

+ 3 - 0
mcs/mcs/codegen.cs

@@ -172,6 +172,9 @@ namespace Mono.CSharp {
 			catch (System.IO.IOException io) {
 				Report.Error (16, "Could not write to file `"+name+"', cause: " + io.Message);
 			}
+			catch (System.UnauthorizedAccessException ua) {
+				Report.Error (16, "Could not write to file `"+name+"', cause: " + ua.Message);
+			}
 
 			if (SymbolWriter != null)
 				SymbolWriter.WriteSymbolFile ();

+ 13 - 6
mcs/mcs/convert.cs

@@ -1036,20 +1036,27 @@ namespace Mono.CSharp {
 			if (method == null || count > 1)
 				return null;
 			
-			
+			Expression original_source = source;
 			//
 			// This will do the conversion to the best match that we
-			// found.  Now we need to perform an implict standard conversion
+			// found.  Now we need to perform an implicit standard conversion
 			// if the best match was not the type that we were requested
 			// by target.
 			//
 			if (look_for_explicit)
-				source = ExplicitConversionStandard (ec, source, most_specific_source, loc);
+				source = ExplicitConversionStandard (ec, original_source, most_specific_source, loc);
 			else
-				source = ImplicitConversionStandard (ec, source, most_specific_source, loc);
+				source = ImplicitConversionStandard (ec, original_source, most_specific_source, loc);
 
-			if (source == null)
-				return null;
+			//
+			// If ImplicitConversionStandard comes up with nothing, try UserDefinedConversion 
+			// again, because a UserCast might be able to cast `original_source' into `most_specific_source'.
+			//
+			if (source == null) {
+				source = UserDefinedConversion (ec, original_source, most_specific_source, loc, false);
+				if (source == null)
+					return null;
+			}
 
 			Expression e;
 			e =  new UserCast ((MethodInfo) method, source, loc);

+ 8 - 0
mcs/mcs/cs-tokenizer.cs

@@ -1947,11 +1947,14 @@ namespace Mono.CSharp
 					} else if (d == '*'){
 						getChar ();
 						bool docAppend = false;
+						bool expecting_end_of_comment = true;
+						
 						if (RootContext.Documentation != null && peekChar () == '*') {
 							getChar ();
 							// But when it is /**/, just do nothing.
 							if (peekChar () == '/') {
 								getChar ();
+								expecting_end_of_comment = false;
 								continue;
 							}
 							if (doc_state == XmlCommentState.Allowed)
@@ -1973,6 +1976,7 @@ namespace Mono.CSharp
 								getChar ();
 								col++;
 								comments_seen = true;
+								expecting_end_of_comment = false;
 								break;
 							}
 							if (docAppend)
@@ -1996,6 +2000,10 @@ namespace Mono.CSharp
 
 						if (docAppend)
 							update_formatted_doc_comment (current_comment_start);
+
+						if (expecting_end_of_comment)
+							Report.Error (1035, Location, "End-of-file found, '*/' expected");
+						
 						continue;
 					}
 					goto is_punct_label;

+ 34 - 6
mcs/mcs/expression.cs

@@ -2400,9 +2400,6 @@ namespace Mono.CSharp {
 
 					if (l == r)
 						return this;
-					
-					if (l.IsSubclassOf (r) || r.IsSubclassOf (l))
-						return this;
 
 					//
 					// Also, a standard conversion must exist from either one
@@ -2421,9 +2418,17 @@ namespace Mono.CSharp {
 						right = new EmptyCast (right, TypeManager.object_type);
 
 					//
-					// FIXME: CSC here catches errors cs254 and cs252
-					//
-					return this;
+					// Report CS0252 / CS0253 if we have to invoke Object.op_Equality
+					// even when either l or r implements of op_Equality.
+					// 
+					if (!HasEqualityOperatorForType (l, r))
+						Warning_UnintendedReferenceComparison (loc, "right", r.FullName);
+					
+					else if (!HasEqualityOperatorForType (r, l))
+						Warning_UnintendedReferenceComparison (loc, "left", l.FullName);
+
+					if (l.IsSubclassOf (r) || r.IsSubclassOf (l))
+						return this;
 				}
 
 				//
@@ -2693,6 +2698,29 @@ namespace Mono.CSharp {
 			return this;
 		}
 
+		// Checks whether or not 'container' has op_Equality that can handle 'comparison_type'.
+		public static bool HasEqualityOperatorForType (Type container, Type comparison_type)
+		{
+			// Can't call GetMethod here as there could be multiple impl. of op_Equality.
+			MethodInfo [] methods = container.GetMethods ();
+			foreach (MethodInfo m in methods) {
+				if (m.Name == "op_Equality") {
+					foreach (ParameterInfo param in m.GetParameters ()) {
+						if (param.ParameterType == comparison_type)
+							return true;
+					}
+				}
+			}
+			return false;
+		}
+
+		public static void Warning_UnintendedReferenceComparison (Location loc, string direction, string type_name)
+		{
+			Report.Warning ((direction == "left" ? 252 : 253), 2, loc,
+					"Possible unintended reference comparison; to get a value comparison, " +
+					"cast the " + direction + " hand side to type " + type_name + ".");
+		}
+
 		public override Expression DoResolve (EmitContext ec)
 		{
 			if ((oper == Operator.Subtraction) && (left is ParenthesizedExpression)) {