[mono/mono] ee09ac3b: Enum subtraction quirk needs to work with numeric constants only. Fixes #15520

"Marek Safar ([email protected])" <[email protected]>
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <00000141f8dcc78b-6821b692-5900-48c8-a7f4-d3d6ee5ea62d-000000@email.amazonses.com>
   Branch: refs/heads/master
     Home: https://github.com/mono/mono
  Compare: https://github.com/mono/mono/compare/0a17e9070dab...ee09ac3bcf7f

   Commit: ee09ac3bcf7f0763b30ac6684079aea38f371306
   Author: Marek Safar <[email protected]> (marek-safar)
     Date: 2013-10-27 07:40:51 GMT
      URL: https://github.com/mono/mono/commit/ee09ac3bcf7f0763b30ac6684079aea38f371306

Enum subtraction quirk needs to work with numeric constants only. Fixes #15520

Changed paths:
  M mcs/mcs/expression.cs
  M mcs/tests/test-869.cs
  M mcs/tests/ver-il-net_4_5.xml

Modified: mcs/mcs/expression.cs
===================================================================
@@ -3749,7 +3749,7 @@ Expression ConvertEnumSubtractionResult (ResolveContext rc, Expression expr)
 			TypeSpec result_type;
 			if (left.Type == right.Type) {
 				var c = right as EnumConstant;
-				if (c != null && c.IsZeroInteger) {
+				if (c != null && c.IsZeroInteger && !right.Type.IsEnum) {
 					//
 					// LAMESPEC: This is quite unexpected for expression E - 0 the return type is
 					// E which is not what expressions E - 1 or 0 - E return

Modified: mcs/tests/test-869.cs
===================================================================
@@ -20,6 +20,13 @@ public enum E
 	Item = 2
 }
 
+enum E2
+{
+	A = 0,
+	B,
+	C
+}
+
 class FooClass
 {
 	public static int Main ()
@@ -34,6 +41,9 @@ public static int Main ()
 		if (res != C.Token)
 			return 2;
 
+		E2 e2 = E2.C;
+
+		int day1 = e2 - E2.A;
 		return 0;	
 	}
 }
\ No newline at end of file

Modified: mcs/tests/ver-il-net_4_5.xml
===================================================================
@@ -48228,7 +48228,7 @@
     </type>
     <type name="FooClass">
       <method name="Int32 Main()" attrs="150">
-        <size>70</size>
+        <size>77</size>
       </method>
       <method name="Void .ctor()" attrs="6278">
         <size>7</size>



_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.