[mcs] Add probing conversion for FormattableString. Fixes #41575
authorMarek Safar <marek.safar@gmail.com>
Thu, 9 Jun 2016 15:54:32 +0000 (17:54 +0200)
committerMarek Safar <marek.safar@gmail.com>
Thu, 9 Jun 2016 15:55:19 +0000 (17:55 +0200)
mcs/mcs/convert.cs
mcs/mcs/mcs.csproj
mcs/tests/test-interpolation-10.cs [new file with mode: 0644]
mcs/tests/ver-il-net_4_x.xml

index 95f9897c081a7dfbe9bde7d9faef9a60baae01dd..36c5626bcc32dd190a10ff102953fb65f56ea8e3 100644 (file)
@@ -715,6 +715,12 @@ namespace Mono.CSharp {
                                return false;
                        }
 
+                       var interpolated_string = expr as InterpolatedString;
+                       if (interpolated_string != null) {
+                               if (target_type == rc.Module.PredefinedTypes.IFormattable.TypeSpec || target_type == rc.Module.PredefinedTypes.FormattableString.TypeSpec)
+                                       return true;
+                       }
+
                        return ImplicitStandardConversionExists (expr, target_type);
                }
 
index b81e6db8138746a8e1b70a3b58feb8b436ad2a0a..812652f925fad15efa145069ddb2ec259faa0f7d 100644 (file)
@@ -22,7 +22,7 @@
     <ErrorReport>prompt</ErrorReport>\r
     <WarningLevel>4</WarningLevel>\r
     <UseVSHostingProcess>false</UseVSHostingProcess>\r
-    <Commandlineparameters>../tests/test-936.cs -r:../tests/test-936-lib.dll</Commandlineparameters>\r
+    <Commandlineparameters>y.cs</Commandlineparameters>\r
   </PropertyGroup>\r
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">\r
     <DebugType>pdbonly</DebugType>\r
diff --git a/mcs/tests/test-interpolation-10.cs b/mcs/tests/test-interpolation-10.cs
new file mode 100644 (file)
index 0000000..15f5e21
--- /dev/null
@@ -0,0 +1,25 @@
+using System;
+
+class Program
+{
+       static int counter;
+
+       static int Main ()
+       {
+               FormatPrint ($"Case {1}");
+               if (counter != 1)
+                       return 1;
+
+               FormatPrint ($"Case {3}");
+               if (counter != 2)
+                       return 2;
+
+               return 0;
+       }
+
+       static void FormatPrint (FormattableString message)
+       {
+               Console.WriteLine(message);
+               ++counter;
+       }
+}
index 21456b93a25cc0bcc07d563fbd7a29e83d80aee4..8d87222999dd12b67d31e7a4da53c4c87042b5e3 100644 (file)
       </method>
     </type>
   </test>
+  <test name="test-interpolation-10.cs">
+    <type name="Program">
+      <method name="Int32 Main()" attrs="145">
+        <size>106</size>
+      </method>
+      <method name="Void FormatPrint(System.FormattableString)" attrs="145">
+        <size>20</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="test-iter-01.cs">
     <type name="X">
       <method name="Int32 Main()" attrs="150">