Author: marek
Date: 2007-11-08 09:59:21 -0500 (Thu, 08 Nov 2007)
New Revision: 89193

Modified:
   trunk/mcs/mcs/ChangeLog
   trunk/mcs/mcs/expression.cs
Log:
2007-11-08  Marek Safar  <[EMAIL PROTECTED]>

        A fix for bug #335594
        * expression.cs: Use conversion rules when handling string addition.
        


Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog     2007-11-08 14:40:53 UTC (rev 89192)
+++ trunk/mcs/mcs/ChangeLog     2007-11-08 14:59:21 UTC (rev 89193)
@@ -1,3 +1,8 @@
+2007-11-08  Marek Safar  <[EMAIL PROTECTED]>
+
+       A fix for bug #335594
+       * expression.cs: Use conversion rules when handling string addition.
+       
 2007-11-07  Marek Safar  <[EMAIL PROTECTED]>
 
        A fix for bug #336651

Modified: trunk/mcs/mcs/expression.cs
===================================================================
--- trunk/mcs/mcs/expression.cs 2007-11-08 14:40:53 UTC (rev 89192)
+++ trunk/mcs/mcs/expression.cs 2007-11-08 14:59:21 UTC (rev 89193)
@@ -1619,6 +1619,14 @@
                {
                        if (!IsApplicable_String (ec, left, right, oper))
                                return false;
+                       
+                       Type l = left.Type;
+                       Type r = right.Type;
+                       if (OverloadResolve_PredefinedIntegral (ec) ||
+                               OverloadResolve_PredefinedFloating (ec)) {
+                               Error_OperatorAmbiguous (loc, oper, l, r);
+                       }
+                       
                        Type t = TypeManager.string_type;
                        if (Convert.ImplicitConversionExists (ec, left, t))
                                left = ForceConversion (ec, left, t);
@@ -1891,39 +1899,37 @@
                        //
                        // Step 0: String concatenation (because overloading 
will get this wrong)
                        //
-                       if (oper == Operator.Addition){
+                       if (oper == Operator.Addition && 
!TypeManager.IsDelegateType (l)) {
+                               // 
+                               // Either left or right expression is 
implicitly convertible to string
                                //
-                               // If any of the arguments is a string, cast to 
string
-                               //
-                               
-                               // Simple constant folding
-                               if (left is StringConstant && right is 
StringConstant)
-                                       return new StringConstant 
(((StringConstant) left).Value + ((StringConstant) right).Value, left.Location);
-                               
-                               if (l == TypeManager.string_type || r == 
TypeManager.string_type) {
-
+                               if (OverloadResolve_PredefinedString (ec, 
oper)) {
                                        if (r == TypeManager.void_type || l == 
TypeManager.void_type) {
                                                Error_OperatorCannotBeApplied 
();
                                                return null;
                                        }
 
-                                       // try to fold it in on the left
+                                       //
+                                       // Constants folding for strings and 
nulls
+                                       //
+                                       if (left.Type == 
TypeManager.string_type && right.Type == TypeManager.string_type &&
+                                               left is Constant && right is 
Constant) {
+                                               string lvalue = 
(string)((Constant) left).GetValue ();
+                                               string rvalue = 
(string)((Constant) right).GetValue ();
+                                               return new StringConstant 
(lvalue + rvalue, left.Location);
+                                       }
+
+                                       // 
+                                       // Append to existing string 
concatenation
+                                       //
                                        if (left is StringConcat) {
-
-                                               //
-                                               // We have to test here for 
not-null, since we can be doubly-resolved
-                                               // take care of not appending 
twice
-                                               //
-                                               if (type == null){
-                                                       type = 
TypeManager.string_type;
-                                                       ((StringConcat) 
left).Append (ec, right);
-                                                       return left.Resolve 
(ec);
-                                               } else {
-                                                       return left;
-                                               }
+                                               ((StringConcat) left).Append 
(ec, right);
+                                               return left;
                                        }
 
-                                       // Otherwise, start a new concat 
expression
+                                       //
+                                       // Otherwise, start a new concat 
expression using converted expression
+                                       //
                                        return new StringConcat (ec, loc, left, 
right).Resolve (ec);
                                }
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to