Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Safar <masafa@microsoft.com>2016-08-02 21:54:03 +0300
committerMarek Safar <masafa@microsoft.com>2016-08-02 21:56:06 +0300
commit7e087da798a029312db1f987edfdc212f08a4422 (patch)
tree23f3fb1592c4fa4564b7d71515cacb205aee001f
parent753c3237d9a6f9b394f2079474147529042f6cd0 (diff)
[mcs] More tweaks in betterness improvements. Fixes #41724
-rw-r--r--mcs/mcs/ecore.cs15
-rw-r--r--mcs/tests/gtest-637.cs26
-rw-r--r--mcs/tests/ver-il-net_4_x.xml21
3 files changed, 58 insertions, 4 deletions
diff --git a/mcs/mcs/ecore.cs b/mcs/mcs/ecore.cs
index e0e5b6f4748..4386f93115a 100644
--- a/mcs/mcs/ecore.cs
+++ b/mcs/mcs/ecore.cs
@@ -4599,10 +4599,11 @@ namespace Mono.CSharp {
return IsBetterConversionTarget (rc, p, q);
}
+ var p_orig = p;
if (p.IsNullableType) {
p = Nullable.NullableInfo.GetUnderlyingType (p);
if (!BuiltinTypeSpec.IsPrimitiveTypeOrDecimal (p))
- return 0;
+ return BetterTypeConversionImplicitConversion (rc, p_orig, q);
//
// Spec expects implicit conversion check between p and q, q and p
@@ -4615,10 +4616,11 @@ namespace Mono.CSharp {
return 2;
}
+ var q_orig = q;
if (q.IsNullableType) {
q = Nullable.NullableInfo.GetUnderlyingType (q);
if (!BuiltinTypeSpec.IsPrimitiveTypeOrDecimal (q))
- return 0;
+ return BetterTypeConversionImplicitConversion (rc, p_orig, q_orig);
if (q == p)
return 1;
@@ -4699,12 +4701,17 @@ namespace Mono.CSharp {
break;
}
+ return BetterTypeConversionImplicitConversion (ec, p, q);
+ }
+
+ static int BetterTypeConversionImplicitConversion (ResolveContext rc, TypeSpec p, TypeSpec q)
+ {
// TODO: this is expensive
Expression p_tmp = new EmptyExpression (p);
Expression q_tmp = new EmptyExpression (q);
- bool p_to_q = Convert.ImplicitConversionExists (ec, p_tmp, q);
- bool q_to_p = Convert.ImplicitConversionExists (ec, q_tmp, p);
+ bool p_to_q = Convert.ImplicitConversionExists (rc, p_tmp, q);
+ bool q_to_p = Convert.ImplicitConversionExists (rc, q_tmp, p);
if (p_to_q && !q_to_p)
return 1;
diff --git a/mcs/tests/gtest-637.cs b/mcs/tests/gtest-637.cs
new file mode 100644
index 00000000000..f08c8502c74
--- /dev/null
+++ b/mcs/tests/gtest-637.cs
@@ -0,0 +1,26 @@
+using System;
+
+public struct nint
+{
+ public static implicit operator nint (int v)
+ {
+ return 0;
+ }
+}
+
+public class MainClass
+{
+ static void Test (string key, int? value)
+ {
+ }
+
+ static void Test (string key, nint? value)
+ {
+ throw new ApplicationException ();
+ }
+
+ public static void Main ()
+ {
+ Test (null, int.MinValue);
+ }
+}
diff --git a/mcs/tests/ver-il-net_4_x.xml b/mcs/tests/ver-il-net_4_x.xml
index 79e1b18bf10..c705efa9a03 100644
--- a/mcs/tests/ver-il-net_4_x.xml
+++ b/mcs/tests/ver-il-net_4_x.xml
@@ -19848,6 +19848,27 @@
</method>
</type>
</test>
+ <test name="gtest-637.cs">
+ <type name="nint">
+ <method name="nint op_Implicit(Int32)" attrs="2198">
+ <size>15</size>
+ </method>
+ </type>
+ <type name="MainClass">
+ <method name="Void Test(System.String, System.Nullable`1[System.Int32])" attrs="145">
+ <size>2</size>
+ </method>
+ <method name="Void Test(System.String, System.Nullable`1[nint])" attrs="145">
+ <size>7</size>
+ </method>
+ <method name="Void Main()" attrs="150">
+ <size>18</size>
+ </method>
+ <method name="Void .ctor()" attrs="6278">
+ <size>7</size>
+ </method>
+ </type>
+ </test>
<test name="gtest-anontype-01.cs">
<type name="Test">
<method name="Int32 Main()" attrs="150">