Fix #82120
authorRaja R Harinath <harinath@hurrynot.org>
Wed, 18 Jul 2007 13:22:34 +0000 (13:22 -0000)
committerRaja R Harinath <harinath@hurrynot.org>
Wed, 18 Jul 2007 13:22:34 +0000 (13:22 -0000)
* mcs/expression.cs (Binary.ResolveOperator): When converting
'a + (- b)' to 'a - b', ensure that the unary '-' is discarded.
* tests/test-576.cs: New test for #82120.

svn path=/trunk/mcs/; revision=82204

mcs/mcs/ChangeLog
mcs/mcs/expression.cs
mcs/tests/ChangeLog
mcs/tests/test-576.cs [new file with mode: 0644]

index 3c11a86493246e49803ea8ec3032664c02c2fa0f..f9b4d1d981c653f936689e2c25041ce8ea2207d7 100644 (file)
@@ -1,3 +1,9 @@
+2007-07-18  Raja R Harinath  <rharinath@novell.com>
+
+       Fix #82120
+       * expression.cs (Binary.ResolveOperator): When converting
+       'a + (- b)' to 'a - b', ensure that the unary '-' is discarded.
+
 2007-07-18  Atsushi Enomoto  <atsushi@ximian.com>
 
        * doc.cs : when T: or whatever x: is specified, it does not really
index 382a89fe02b3e5465c5eca14e5018d678392d3b7..390c782d6191b5ee4d9fd8bb051ea66776de7729 100644 (file)
@@ -1868,7 +1868,7 @@ namespace Mono.CSharp {
                                        Unary right_unary = (Unary) right;
 
                                        if (right_unary.Oper == Unary.Operator.UnaryNegation){
-                                               return new Binary (Operator.Subtraction, left, right).Resolve (ec);
+                                               return new Binary (Operator.Subtraction, left, right_unary.Expr).Resolve (ec);
                                        }
                                }
                        }
index 170fa4d18079de5c2609df713daa09d3e6e38718..e4c57de95ab9131bbb1291d583d0e107e63c2f43 100644 (file)
@@ -1,3 +1,7 @@
+2007-07-18  Raja R Harinath  <rharinath@novell.com>
+
+       * test-576.cs: New test for #82120.
+
 2007-07-18  Atsushi Enomoto  <atsushi@ximian.com>
 
        * gtest-xml-2.cs, gtest-xml-2-ref.xml : new /doc test for bug #82006.
diff --git a/mcs/tests/test-576.cs b/mcs/tests/test-576.cs
new file mode 100644 (file)
index 0000000..bcf74ad
--- /dev/null
@@ -0,0 +1,10 @@
+class Foo {
+       static void Main ()
+       {
+               int a = 0;
+               int b = 5;
+               a += -b;
+               if (a != -5)
+                       throw new System.Exception ();
+       }
+}