[mcs] Fixes codegen of predefined pointer arithmetic operators with user defined...
authorMarek Safar <marek.safar@gmail.com>
Mon, 19 Sep 2016 14:47:21 +0000 (16:47 +0200)
committerMarek Safar <marek.safar@gmail.com>
Mon, 19 Sep 2016 14:47:21 +0000 (16:47 +0200)
mcs/mcs/expression.cs
mcs/tests/test-940.cs [new file with mode: 0644]
mcs/tests/ver-il-net_4_x.xml

index ae27eb24900d5eed8c6ee3ae36589ff54643b1cc..2968ee08584f544f7869efba43e4007b9f259888 100644 (file)
@@ -3110,9 +3110,9 @@ namespace Mono.CSharp
                        public override Expression ConvertResult (ResolveContext ec, Binary b)
                        {
                                if (left != null) {
-                                       b.left = EmptyCast.Create (b.left, left);
+                                       b.left = Convert.UserDefinedConversion (ec, b.left, left, Convert.UserConversionRestriction.ImplicitOnly, b.loc) ?? EmptyCast.Create (b.left, left);
                                } else if (right != null) {
-                                       b.right = EmptyCast.Create (b.right, right);
+                                       b.right = Convert.UserDefinedConversion (ec, b.right, right, Convert.UserConversionRestriction.ImplicitOnly, b.loc) ?? EmptyCast.Create (b.right, right);
                                }
 
                                TypeSpec r_type = ReturnType;
diff --git a/mcs/tests/test-940.cs b/mcs/tests/test-940.cs
new file mode 100644 (file)
index 0000000..d7c68f0
--- /dev/null
@@ -0,0 +1,31 @@
+// Compiler options: -unsafe
+
+using System;
+
+struct nint
+{
+       public static nint operator * (nint a, nint b)
+       {
+               return a;
+       }
+
+       public static implicit operator long (nint v)
+       {
+               return 0;
+       }
+}
+
+class X
+{
+       public static void Main ()
+       {
+               nint width;
+               nint bytesPerRow;
+
+               unsafe {
+                       var da = (uint*)0;
+                       var dp1 = da + width * bytesPerRow;
+                       var dp2 = width * bytesPerRow + da;
+               }
+       }
+}
\ No newline at end of file
index 2ef20e19608c53fa53918153e1d01fa2feacff8b..0cbfab7639446a263dbd2ddf710b6179d65babaa 100644 (file)
       </method>
     </type>
   </test>
+  <test name="test-940.cs">
+    <type name="nint">
+      <method name="nint op_Multiply(nint, nint)" attrs="2198">
+        <size>10</size>
+      </method>
+      <method name="Int64 op_Implicit(nint)" attrs="2198">
+        <size>11</size>
+      </method>
+    </type>
+    <type name="X">
+      <method name="Void Main()" attrs="150">
+        <size>46</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="test-95.cs">
     <type name="X">
       <method name="Int32 Main()" attrs="150">