diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs index 6d829cd9dcdf2..6b2079bf5f1a6 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs @@ -4873,6 +4873,7 @@ public void HandlerConversionPreferredOverStringForNonConstant(string expression var code = @" CultureInfoNormalizer.Normalize(); C.M(" + expression + @"); +CultureInfoNormalizer.Reset(); class C { public static void M(CustomHandler b) @@ -4896,7 +4897,7 @@ public static void M(string s) verifier.VerifyIL(@"", @" { - // Code size 55 (0x37) + // Code size 60 (0x3c) .maxstack 4 .locals init (CustomHandler V_0) IL_0000: call ""void CultureInfoNormalizer.Normalize()"" @@ -4919,7 +4920,8 @@ .locals init (CustomHandler V_0) IL_002f: pop IL_0030: ldloc.0 IL_0031: call ""void C.M(CustomHandler)"" - IL_0036: ret + IL_0036: call ""void CultureInfoNormalizer.Reset()"" + IL_003b: ret } "); @@ -4928,7 +4930,7 @@ .locals init (CustomHandler V_0) verifier.VerifyIL(@"", expression.Contains('+') ? @" { - // Code size 37 (0x25) + // Code size 42 (0x2a) .maxstack 2 IL_0000: call ""void CultureInfoNormalizer.Normalize()"" IL_0005: ldstr ""{0,2:f}"" @@ -4938,12 +4940,13 @@ .maxstack 2 IL_0015: ldstr ""Literal"" IL_001a: call ""string string.Concat(string, string)"" IL_001f: call ""void C.M(string)"" - IL_0024: ret + IL_0024: call ""void CultureInfoNormalizer.Reset()"" + IL_0029: ret } " : @" { - // Code size 27 (0x1b) + // Code size 32 (0x20) .maxstack 2 IL_0000: call ""void CultureInfoNormalizer.Normalize()"" IL_0005: ldstr ""{0,2:f}Literal"" @@ -4951,7 +4954,8 @@ .maxstack 2 IL_000b: box ""int"" IL_0010: call ""string string.Format(string, object)"" IL_0015: call ""void C.M(string)"" - IL_001a: ret + IL_001a: call ""void CultureInfoNormalizer.Reset()"" + IL_001f: ret } "); } @@ -5422,6 +5426,7 @@ public void LambdaReturnInference_02(string expression) using System; CultureInfoNormalizer.Normalize(); C.M(() => " + expression + @"); +CultureInfoNormalizer.Reset(); class C { @@ -5669,6 +5674,7 @@ public void LambdaReturnInference_06(string expression) if (b) return default(CustomHandler); else return " + expression + @"; }); +CultureInfoNormalizer.Reset(); static class C { @@ -5922,6 +5928,7 @@ public void TernaryTypes_02(string expression) CultureInfoNormalizer.Normalize(); var x = (bool)(object)false ? default(CustomHandler) : " + expression + @"; Console.WriteLine(x); +CultureInfoNormalizer.Reset(); public partial struct CustomHandler { @@ -5934,7 +5941,7 @@ public partial struct CustomHandler verifier.VerifyIL("", !expression.Contains('+') ? @" { - // Code size 56 (0x38) + // Code size 61 (0x3d) .maxstack 2 .locals init (CustomHandler V_0) IL_0000: call ""void CultureInfoNormalizer.Normalize()"" @@ -5952,12 +5959,13 @@ .locals init (CustomHandler V_0) IL_002c: ldloc.0 IL_002d: call ""string CustomHandler.op_Implicit(CustomHandler)"" IL_0032: call ""void System.Console.WriteLine(string)"" - IL_0037: ret + IL_0037: call ""void CultureInfoNormalizer.Reset()"" + IL_003c: ret } " : @" { - // Code size 66 (0x42) + // Code size 71 (0x47) .maxstack 2 .locals init (CustomHandler V_0) IL_0000: call ""void CultureInfoNormalizer.Normalize()"" @@ -5977,7 +5985,8 @@ .locals init (CustomHandler V_0) IL_0036: ldloc.0 IL_0037: call ""string CustomHandler.op_Implicit(CustomHandler)"" IL_003c: call ""void System.Console.WriteLine(string)"" - IL_0041: ret + IL_0041: call ""void CultureInfoNormalizer.Reset()"" + IL_0046: ret } "); } @@ -6190,6 +6199,7 @@ public void SwitchTypes_02(string expression) CultureInfoNormalizer.Normalize(); var x = (bool)(object)false switch { true => default(CustomHandler), false => " + expression + @" }; Console.WriteLine(x); +CultureInfoNormalizer.Reset(); public partial struct CustomHandler { @@ -6202,7 +6212,7 @@ public partial struct CustomHandler verifier.VerifyIL("", !expression.Contains('+') ? @" { - // Code size 59 (0x3b) + // Code size 64 (0x40) .maxstack 2 .locals init (string V_0, CustomHandler V_1) @@ -6224,12 +6234,13 @@ .locals init (string V_0, IL_0033: stloc.0 IL_0034: ldloc.0 IL_0035: call ""void System.Console.WriteLine(string)"" - IL_003a: ret + IL_003a: call ""void CultureInfoNormalizer.Reset()"" + IL_003f: ret } " : @" { - // Code size 69 (0x45) + // Code size 74 (0x4a) .maxstack 2 .locals init (string V_0, CustomHandler V_1) @@ -6253,7 +6264,8 @@ .locals init (string V_0, IL_003d: stloc.0 IL_003e: ldloc.0 IL_003f: call ""void System.Console.WriteLine(string)"" - IL_0044: ret + IL_0044: call ""void CultureInfoNormalizer.Reset()"" + IL_0049: ret } "); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RawInterpolationTests_Handler.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RawInterpolationTests_Handler.cs index bde5a43a8840b..ee7f1463e8e58 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RawInterpolationTests_Handler.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RawInterpolationTests_Handler.cs @@ -3633,6 +3633,7 @@ public void LambdaReturnInference_02(string expression) using System; CultureInfoNormalizer.Normalize(); C.M(() => " + expression + @"); +CultureInfoNormalizer.Reset(); class C { @@ -3902,6 +3903,7 @@ public void LambdaReturnInference_06(string expression) if (b) return default(CustomHandler); else return " + expression + @"; }); +CultureInfoNormalizer.Reset(); static class C { @@ -4178,6 +4180,7 @@ public void TernaryTypes_02(string expression) CultureInfoNormalizer.Normalize(); var x = (bool)(object)false ? default(CustomHandler) : " + expression + @"; Console.WriteLine(x); +CultureInfoNormalizer.Reset(); public partial struct CustomHandler { @@ -4190,7 +4193,7 @@ public partial struct CustomHandler verifier.VerifyIL("", !expression.Contains('+') ? @" { - // Code size 56 (0x38) + // Code size 61 (0x3d) .maxstack 2 .locals init (CustomHandler V_0) IL_0000: call ""void CultureInfoNormalizer.Normalize()"" @@ -4208,12 +4211,13 @@ .locals init (CustomHandler V_0) IL_002c: ldloc.0 IL_002d: call ""string CustomHandler.op_Implicit(CustomHandler)"" IL_0032: call ""void System.Console.WriteLine(string)"" - IL_0037: ret + IL_0037: call ""void CultureInfoNormalizer.Reset()"" + IL_003c: ret } " : @" { - // Code size 66 (0x42) + // Code size 71 (0x47) .maxstack 2 .locals init (CustomHandler V_0) IL_0000: call ""void CultureInfoNormalizer.Normalize()"" @@ -4233,7 +4237,8 @@ .locals init (CustomHandler V_0) IL_0036: ldloc.0 IL_0037: call ""string CustomHandler.op_Implicit(CustomHandler)"" IL_003c: call ""void System.Console.WriteLine(string)"" - IL_0041: ret + IL_0041: call ""void CultureInfoNormalizer.Reset()"" + IL_0046: ret } "); } @@ -4443,6 +4448,7 @@ public void SwitchTypes_02(string expression) CultureInfoNormalizer.Normalize(); var x = (bool)(object)false switch { true => default(CustomHandler), false => " + expression + @" }; Console.WriteLine(x); +CultureInfoNormalizer.Reset(); public partial struct CustomHandler { @@ -4455,7 +4461,7 @@ public partial struct CustomHandler verifier.VerifyIL("", !expression.Contains('+') ? @" { - // Code size 59 (0x3b) + // Code size 64 (0x40) .maxstack 2 .locals init (string V_0, CustomHandler V_1) @@ -4477,12 +4483,13 @@ .locals init (string V_0, IL_0033: stloc.0 IL_0034: ldloc.0 IL_0035: call ""void System.Console.WriteLine(string)"" - IL_003a: ret + IL_003a: call ""void CultureInfoNormalizer.Reset()"" + IL_003f: ret } " : @" { - // Code size 69 (0x45) + // Code size 74 (0x4a) .maxstack 2 .locals init (string V_0, CustomHandler V_1) @@ -4506,7 +4513,8 @@ .locals init (string V_0, IL_003d: stloc.0 IL_003e: ldloc.0 IL_003f: call ""void System.Console.WriteLine(string)"" - IL_0044: ret + IL_0044: call ""void CultureInfoNormalizer.Reset()"" + IL_0049: ret } "); } diff --git a/src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs b/src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs index 166457fffd27e..32197356378ef 100644 --- a/src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs +++ b/src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs @@ -2544,10 +2544,18 @@ internal static string GetInterpolatedStringCustomHandlerType(string name, strin var cultureInfoHandler = @" public class CultureInfoNormalizer { + private static CultureInfo originalCulture; + public static void Normalize() { + originalCulture = CultureInfo.CurrentCulture; CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; } + + public static void Reset() + { + CultureInfo.CurrentCulture = originalCulture; + } } ";