diff --git a/src/Analyzers/CSharp/Tests/RemoveUnnecessaryCast/RemoveUnnecessaryCastTests.cs b/src/Analyzers/CSharp/Tests/RemoveUnnecessaryCast/RemoveUnnecessaryCastTests.cs index 34243c596fe4e..39a93621384bd 100644 --- a/src/Analyzers/CSharp/Tests/RemoveUnnecessaryCast/RemoveUnnecessaryCastTests.cs +++ b/src/Analyzers/CSharp/Tests/RemoveUnnecessaryCast/RemoveUnnecessaryCastTests.cs @@ -12,5584 +12,5584 @@ using Roslyn.Test.Utilities; using Xunit; -namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.RemoveUnnecessaryCast; - -using VerifyCS = CSharpCodeFixVerifier< - CSharpRemoveUnnecessaryCastDiagnosticAnalyzer, - CSharpRemoveUnnecessaryCastCodeFixProvider>; - -[Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnnecessaryCast)] -public class RemoveUnnecessaryCastTests +namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.RemoveUnnecessaryCast { - [Theory, CombinatorialData] - public void TestStandardProperty(AnalyzerProperty property) - => VerifyCS.VerifyStandardProperty(property); + using VerifyCS = CSharpCodeFixVerifier< + CSharpRemoveUnnecessaryCastDiagnosticAnalyzer, + CSharpRemoveUnnecessaryCastCodeFixProvider>; - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545979")] - public async Task DoNotRemoveCastToErrorType() + [Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnnecessaryCast)] + public class RemoveUnnecessaryCastTests { - var source = - """ - class Program - { - static void Main() + [Theory, CombinatorialData] + public void TestStandardProperty(AnalyzerProperty property) + => VerifyCS.VerifyStandardProperty(property); + + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545979")] + public async Task DoNotRemoveCastToErrorType() + { + var source = + """ + class Program { - object s = "; - foreach (object x in ({|CS0246:ErrorType|})s) + static void Main() { + object s = "; + foreach (object x in ({|CS0246:ErrorType|})s) + { + } } } - } - """; - - await VerifyCS.VerifyCodeFixAsync( - source, - [ - // /0/Test0.cs(5,20): error CS1010: Newline in constant - DiagnosticResult.CompilerError("CS1010").WithSpan(5, 20, 5, 20), - // /0/Test0.cs(5,22): error CS1002: ; expected - DiagnosticResult.CompilerError("CS1002").WithSpan(5, 22, 5, 22), - ], - source); - } - - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545137"), WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/870550")] - public async Task ParenthesizeToKeepParseTheSame1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class Program - { - static void Main() + """; + + await VerifyCS.VerifyCodeFixAsync( + source, + [ + // /0/Test0.cs(5,20): error CS1010: Newline in constant + DiagnosticResult.CompilerError("CS1010").WithSpan(5, 20, 5, 20), + // /0/Test0.cs(5,22): error CS1002: ; expected + DiagnosticResult.CompilerError("CS1002").WithSpan(5, 22, 5, 22), + ], + source); + } + + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545137"), WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/870550")] + public async Task ParenthesizeToKeepParseTheSame1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class Program { - int x = 2; - int i = 1; - Goo(x < [|(int)|]i, x > (2 + 3)); - } + static void Main() + { + int x = 2; + int i = 1; + Goo(x < [|(int)|]i, x > (2 + 3)); + } - static void Goo(bool a, bool b) { } - } - """, + static void Goo(bool a, bool b) { } + } + """, - """ - class Program - { - static void Main() + """ + class Program { - int x = 2; - int i = 1; - Goo(x < (i), x > (2 + 3)); - } + static void Main() + { + int x = 2; + int i = 1; + Goo(x < (i), x > (2 + 3)); + } - static void Goo(bool a, bool b) { } - } - """); - } + static void Goo(bool a, bool b) { } + } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545146")] - public async Task ParenthesizeToKeepParseTheSame2() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545146")] + public async Task ParenthesizeToKeepParseTheSame2() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - class C - { - static void Main() + class C { - Action a = Console.WriteLine; - ([|(Action)|]a)(); + static void Main() + { + Action a = Console.WriteLine; + ([|(Action)|]a)(); + } } - } - """, + """, - """ - using System; + """ + using System; - class C - { - static void Main() + class C { - Action a = Console.WriteLine; - a(); + static void Main() + { + Action a = Console.WriteLine; + a(); + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545160")] - public async Task ParenthesizeToKeepParseTheSame3() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545160")] + public async Task ParenthesizeToKeepParseTheSame3() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - class Program - { - static void Main() + class Program { - var x = (Decimal)[|(int)|]-1; + static void Main() + { + var x = (Decimal)[|(int)|]-1; + } } - } - """, + """, - """ - using System; + """ + using System; - class Program - { - static void Main() + class Program { - var x = (Decimal)(-1); + static void Main() + { + var x = (Decimal)(-1); + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545138")] - public async Task DoNotRemoveTypeParameterCastToObject() - { - var source = - """ - class D - { - void Goo(T obj) + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545138")] + public async Task DoNotRemoveTypeParameterCastToObject() + { + var source = + """ + class D { - int x = (int)(object)obj; + void Goo(T obj) + { + int x = (int)(object)obj; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545139")] - public async Task DoNotRemoveCastInIsTest() - { - var source = - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545139")] + public async Task DoNotRemoveCastInIsTest() + { + var source = + """ + using System; - class D - { - static void Main() + class D { - DayOfWeek[] a = { }; - Console.WriteLine((object)a is int[]); + static void Main() + { + DayOfWeek[] a = { }; + Console.WriteLine((object)a is int[]); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545142")] - public async Task DoNotRemoveCastNeedForUserDefinedOperator() - { - var source = - """ - class A - { - public static implicit operator A(string x) + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545142")] + public async Task DoNotRemoveCastNeedForUserDefinedOperator() + { + var source = + """ + class A { - return new A(); + public static implicit operator A(string x) + { + return new A(); + } } - } - class Program - { - static void Main() + class Program { - A x = (string)null; + static void Main() + { + A x = (string)null; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545142")] - public async Task DoRemoveCastNotNeededForUserDefinedOperator() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class A - { - public static implicit operator A(string x) + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545142")] + public async Task DoRemoveCastNotNeededForUserDefinedOperator() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class A { - return new A(); + public static implicit operator A(string x) + { + return new A(); + } } - } - class Program - { - static void Main() + class Program { - A x = [|(string)|]""; + static void Main() + { + A x = [|(string)|]""; + } } - } - """, """ - class A - { - public static implicit operator A(string x) + """, """ + class A { - return new A(); + public static implicit operator A(string x) + { + return new A(); + } } - } - class Program - { - static void Main() + class Program { - A x = ""; + static void Main() + { + A x = ""; + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545143")] - public async Task DoNotRemovePointerCast1() - { - var source = - """ - unsafe class C - { - static unsafe void Main() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545143")] + public async Task DoNotRemovePointerCast1() + { + var source = + """ + unsafe class C { - var x = (int)(int*)null; + static unsafe void Main() + { + var x = (int)(int*)null; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545144")] - public async Task DoNotRemoveCastToObjectFromDelegateComparison() - { - // The cast below can't be removed because it would result in the Delegate - // op_Equality operator overload being used over reference equality. + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545144")] + public async Task DoNotRemoveCastToObjectFromDelegateComparison() + { + // The cast below can't be removed because it would result in the Delegate + // op_Equality operator overload being used over reference equality. - var source = - """ - using System; + var source = + """ + using System; - class Program - { - static void Main() + class Program { - Action a = Console.WriteLine; - Action b = Console.WriteLine; - Console.WriteLine(a == (object)b); + static void Main() + { + Action a = Console.WriteLine; + Action b = Console.WriteLine; + Console.WriteLine(a == (object)b); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545145")] - public async Task DoNotRemoveCastToAnonymousMethodWhenOnLeftOfAsCast() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545145")] + public async Task DoNotRemoveCastToAnonymousMethodWhenOnLeftOfAsCast() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - class C - { - static void Main() + class C { - var x = (Action)delegate { - } + static void Main() + { + var x = (Action)delegate { + } - [|as Action|]; + [|as Action|]; + } } - } - """, - """ - using System; + """, + """ + using System; - class C - { - static void Main() + class C { - var x = (Action)delegate { - }; + static void Main() + { + var x = (Action)delegate { + }; + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545147")] - public async Task DoNotRemoveCastInFloatingPointOperation() - { - var source = - """ - class C - { - static void Main() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545147")] + public async Task DoNotRemoveCastInFloatingPointOperation() + { + var source = + """ + class C { - int x = 1; - double y = (double)x / 2; + static void Main() + { + int x = 1; + double y = (double)x / 2; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545157")] - public async Task DoNotRemoveIdentityCastWhichAffectsOverloadResolution1() - { - var source = - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545157")] + public async Task DoNotRemoveIdentityCastWhichAffectsOverloadResolution1() + { + var source = + """ + using System; - class Program - { - static void Main() + class Program { - Goo(x => (int)x); - } + static void Main() + { + Goo(x => (int)x); + } - static void Goo(Func x) - { - } + static void Goo(Func x) + { + } - static void Goo(Func x) - { + static void Goo(Func x) + { + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545158")] - public async Task DoNotRemoveIdentityCastWhichAffectsOverloadResolution2() - { - var source = - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545158")] + public async Task DoNotRemoveIdentityCastWhichAffectsOverloadResolution2() + { + var source = + """ + using System; - class Program - { - static void Main() + class Program { - var x = (IComparable)1; - Goo(x); - } + static void Main() + { + var x = (IComparable)1; + Goo(x); + } - static void Goo(IComparable x) - { - } + static void Goo(IComparable x) + { + } - static void Goo(int x) - { + static void Goo(int x) + { + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545158")] - public async Task DoNotRemoveIdentityCastWhichAffectsOverloadResolution3() - { - var source = - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545158")] + public async Task DoNotRemoveIdentityCastWhichAffectsOverloadResolution3() + { + var source = + """ + using System; - class Program - { - static void Main() + class Program { - var x = (IComparable)1; - var y = x; - Goo(y); - } + static void Main() + { + var x = (IComparable)1; + var y = x; + Goo(y); + } - static void Goo(IComparable x) - { - } + static void Goo(IComparable x) + { + } - static void Goo(int x) - { + static void Goo(int x) + { + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545747")] - public async Task DoNotRemoveCastWhichChangesTypeOfInferredLocal() - { - var source = - """ - class C - { - static void Main() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545747")] + public async Task DoNotRemoveCastWhichChangesTypeOfInferredLocal() + { + var source = + """ + class C { - var x = (long)1; - x = long.MaxValue; + static void Main() + { + var x = (long)1; + x = long.MaxValue; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545159")] - public async Task DoNotRemoveNeededCastToIListOfObject() - { - var source = - """ - using System; - using System.Collections.Generic; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545159")] + public async Task DoNotRemoveNeededCastToIListOfObject() + { + var source = + """ + using System; + using System.Collections.Generic; - class C - { - static void Main() + class C { - Action[] x = { - }; - Goo(x); - } + static void Main() + { + Action[] x = { + }; + Goo(x); + } - static void Goo(Action[] x) - { - var y = (IList>)(IList)x; - Console.WriteLine(y.Count); + static void Goo(Action[] x) + { + var y = (IList>)(IList)x; + Console.WriteLine(y.Count); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545287"), WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/880752")] - public async Task RemoveUnneededCastInParameterDefaultValue() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class Program - { - static void M1(int? i1 = [|(int?)|]null) + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545287"), WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/880752")] + public async Task RemoveUnneededCastInParameterDefaultValue() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class Program { + static void M1(int? i1 = [|(int?)|]null) + { + } } - } - """, + """, - """ - class Program - { - static void M1(int? i1 = null) + """ + class Program { + static void M1(int? i1 = null) + { + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545289")] - public async Task RemoveUnneededCastInReturnStatement() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class Program - { - static long M2() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545289")] + public async Task RemoveUnneededCastInReturnStatement() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class Program { - return [|(long)|]5; + static long M2() + { + return [|(long)|]5; + } } - } - """, + """, - """ - class Program - { - static long M2() + """ + class Program { - return 5; + static long M2() + { + return 5; + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545288")] - public async Task RemoveUnneededCastInLambda1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - class Program - { - static void M1() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545288")] + public async Task RemoveUnneededCastInLambda1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + class Program { - Func f1 = () => [|(long)|]5; + static void M1() + { + Func f1 = () => [|(long)|]5; + } } - } - """, + """, - """ - using System; - class Program - { - static void M1() + """ + using System; + class Program { - Func f1 = () => 5; + static void M1() + { + Func f1 = () => 5; + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545288")] - public async Task RemoveUnneededCastInLambda2() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - class Program - { - static void M1() - { - Func f1 = () => { return [|(long)|]5; }; - } - } - """, + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545288")] + public async Task RemoveUnneededCastInLambda2() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + class Program + { + static void M1() + { + Func f1 = () => { return [|(long)|]5; }; + } + } + """, - """ - using System; - class Program - { - static void M1() + """ + using System; + class Program { - Func f1 = () => { return 5; }; + static void M1() + { + Func f1 = () => { return 5; }; + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545288")] - public async Task RemoveUnneededCastInLambda3() - { - var source = - """ - using System; - class Program - { - static void M1() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545288")] + public async Task RemoveUnneededCastInLambda3() + { + var source = + """ + using System; + class Program { - Func f1 = () => { return [|(long)|]5; }; + static void M1() + { + Func f1 = () => { return [|(long)|]5; }; + } } - } - """; - var fixedSource = - """ - using System; - class Program - { - static void M1() + """; + var fixedSource = + """ + using System; + class Program { - Func f1 = () => { return 5; }; + static void M1() + { + Func f1 = () => { return 5; }; + } } - } - """; + """; - await new VerifyCS.Test - { - TestState = - { - Sources = { source }, - }, - FixedState = + await new VerifyCS.Test { - Sources = { fixedSource }, - }, - }.RunAsync(); - } + TestState = + { + Sources = { source }, + }, + FixedState = + { + Sources = { fixedSource }, + }, + }.RunAsync(); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545288")] - public async Task RemoveUnneededCastInLambda4() - { - var source = - """ - using System; - class Program - { - static void M1() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545288")] + public async Task RemoveUnneededCastInLambda4() + { + var source = + """ + using System; + class Program { - Func f1 = () => [|(long)|]5; + static void M1() + { + Func f1 = () => [|(long)|]5; + } } - } - """; - var fixedSource = - """ - using System; - class Program - { - static void M1() + """; + var fixedSource = + """ + using System; + class Program { - Func f1 = () => 5; + static void M1() + { + Func f1 = () => 5; + } } - } - """; + """; - await new VerifyCS.Test - { - TestState = + await new VerifyCS.Test { - Sources = { source }, - }, - FixedState = - { - Sources = { fixedSource }, - }, - }.RunAsync(); - } + TestState = + { + Sources = { source }, + }, + FixedState = + { + Sources = { fixedSource }, + }, + }.RunAsync(); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545291")] - public async Task RemoveUnneededCastInConditionalExpression1() - { - var source = - """ - class Test - { - public static void Main() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545291")] + public async Task RemoveUnneededCastInConditionalExpression1() + { + var source = + """ + class Test { - int b = 5; + public static void Main() + { + int b = 5; - long f1 = (b == 5) ? [|(long)|]4 : [|(long)|]5; + long f1 = (b == 5) ? [|(long)|]4 : [|(long)|]5; + } } - } - """; - var fixedSource = - """ - class Test - { - public static void Main() + """; + var fixedSource = + """ + class Test { - int b = 5; + public static void Main() + { + int b = 5; - long f1 = (b == 5) ? 4 : 5; + long f1 = (b == 5) ? 4 : 5; + } } - } - """; + """; - await new VerifyCS.Test - { - TestState = - { - Sources = { source }, - }, - FixedState = + await new VerifyCS.Test { - Sources = { fixedSource }, - }, - }.RunAsync(); - } + TestState = + { + Sources = { source }, + }, + FixedState = + { + Sources = { fixedSource }, + }, + }.RunAsync(); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545291")] - public async Task DoNotRemoveUnneededCastInConditionalExpression3() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class Test - { - public static void Main() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545291")] + public async Task DoNotRemoveUnneededCastInConditionalExpression3() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class Test { - int b = 5; + public static void Main() + { + int b = 5; - long f1 = (b == 5) ? 4 : [|(long)|]5; + long f1 = (b == 5) ? 4 : [|(long)|]5; + } } - } - """, - """ - class Test - { - public static void Main() + """, + """ + class Test { - int b = 5; + public static void Main() + { + int b = 5; - long f1 = (b == 5) ? 4 : 5; + long f1 = (b == 5) ? 4 : 5; + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545291")] - public async Task DoNotRemoveNeededCastInConditionalExpression() - { - var source = - """ - class Test - { - public static void Main() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545291")] + public async Task DoNotRemoveNeededCastInConditionalExpression() + { + var source = + """ + class Test { - int b = 5; - var f1 = (b == 5) ? 4 : (long)5; + public static void Main() + { + int b = 5; + var f1 = (b == 5) ? 4 : (long)5; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545291")] - public async Task RemoveUnneededCastInConditionalExpression4() - { - var source = - """ - class Test - { - public static void Main() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545291")] + public async Task RemoveUnneededCastInConditionalExpression4() + { + var source = + """ + class Test { - int b = 5; + public static void Main() + { + int b = 5; - var f1 = (b == 5) ? [|(long)|]4 : [|(long)|]5; + var f1 = (b == 5) ? [|(long)|]4 : [|(long)|]5; + } } - } - """; - var fixedSource = - """ - class Test - { - public static void Main() + """; + var fixedSource = + """ + class Test { - int b = 5; + public static void Main() + { + int b = 5; - var f1 = (b == 5) ? (long)4 : 5; + var f1 = (b == 5) ? (long)4 : 5; + } } - } - """; - var batchFixedSource = - """ - class Test - { - public static void Main() + """; + var batchFixedSource = + """ + class Test { - int b = 5; + public static void Main() + { + int b = 5; - var f1 = (b == 5) ? 4 : (long)5; + var f1 = (b == 5) ? 4 : (long)5; + } } - } - """; - - await new VerifyCS.Test - { - TestCode = source, - FixedCode = fixedSource, - BatchFixedCode = batchFixedSource, - CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne, - DiagnosticSelector = diagnostics => diagnostics[1], - }.RunAsync(); - } + """; - [Fact(Skip = "https://github.com/dotnet/roslyn/issues/56938")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545459")] - public async Task RemoveUnneededCastInsideADelegateConstructor() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - class Test + await new VerifyCS.Test { - delegate void D(int x); + TestCode = source, + FixedCode = fixedSource, + BatchFixedCode = batchFixedSource, + CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne, + DiagnosticSelector = diagnostics => diagnostics[1], + }.RunAsync(); + } - static void Main(string[] args) + [Fact(Skip = "https://github.com/dotnet/roslyn/issues/56938")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545459")] + public async Task RemoveUnneededCastInsideADelegateConstructor() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + class Test { - var cd1 = new D([|(Action)|]M1); - } + delegate void D(int x); - public static void M1(int i) { } - } - """, + static void Main(string[] args) + { + var cd1 = new D([|(Action)|]M1); + } - """ - using System; - class Test - { - delegate void D(int x); + public static void M1(int i) { } + } + """, - static void Main(string[] args) + """ + using System; + class Test { - var cd1 = new D(M1); - } + delegate void D(int x); - public static void M1(int i) { } - } - """); - } + static void Main(string[] args) + { + var cd1 = new D(M1); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545419")] - public async Task DoNotRemoveTriviaWhenRemovingCast() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - class Test - { - public static void Main() + public static void M1(int i) { } + } + """); + } + + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545419")] + public async Task DoNotRemoveTriviaWhenRemovingCast() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + class Test { - Func> f2 = () => + public static void Main() { - return [|(Func)|](/*Lambda returning int const*/() => 5 /*Const returned is 5*/); - }; + Func> f2 = () => + { + return [|(Func)|](/*Lambda returning int const*/() => 5 /*Const returned is 5*/); + }; + } } - } - """, + """, - """ - using System; - class Test - { - public static void Main() + """ + using System; + class Test { - Func> f2 = () => + public static void Main() { - return /*Lambda returning int const*/() => 5 /*Const returned is 5*/; - }; + Func> f2 = () => + { + return /*Lambda returning int const*/() => 5 /*Const returned is 5*/; + }; + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545422")] - public async Task RemoveUnneededCastInsideCaseLabel() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class Test - { - static void Main() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545422")] + public async Task RemoveUnneededCastInsideCaseLabel() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class Test { - switch (5L) + static void Main() { - case [|(long)|]5: - break; + switch (5L) + { + case [|(long)|]5: + break; + } } } - } - """, + """, - """ - class Test - { - static void Main() + """ + class Test { - switch (5L) + static void Main() { - case 5: - break; + switch (5L) + { + case 5: + break; + } } } - } - """); - } + """); + } - [Fact(Skip = "https://github.com/dotnet/roslyn/issues/56938")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545578")] - public async Task RemoveUnneededCastInsideGotoCaseStatement() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class Test - { - static void Main() + [Fact(Skip = "https://github.com/dotnet/roslyn/issues/56938")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545578")] + public async Task RemoveUnneededCastInsideGotoCaseStatement() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class Test { - switch (5L) + static void Main() { - case 5: - goto case [|(long)|]5; - break; + switch (5L) + { + case 5: + goto case [|(long)|]5; + break; + } } } - } - """, + """, - """ - class Test - { - static void Main() + """ + class Test { - switch (5L) + static void Main() { - case 5: - goto case 5; - break; + switch (5L) + { + case 5: + goto case 5; + break; + } } } - } - """); - } + """); + } - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545595")] - [WpfFact(Skip = "529787")] - public async Task RemoveUnneededCastInCollectionInitializer() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System.Collections.Generic; + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545595")] + [Fact(Skip = "529787")] + public async Task RemoveUnneededCastInCollectionInitializer() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System.Collections.Generic; - class Program - { - static void Main() + class Program { - var z = new List { [|(long)0|] }; + static void Main() + { + var z = new List { [|(long)0|] }; + } } - } - """, + """, - """ - using System.Collections.Generic; + """ + using System.Collections.Generic; - class Program - { - static void Main() + class Program { - var z = new List { 0 }; + static void Main() + { + var z = new List { 0 }; + } } - } - """); - } + """); + } - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529787")] - [WpfFact(Skip = "529787")] - public async Task DoNotRemoveNecessaryCastWhichInCollectionInitializer1() - { - var source = - """ - using System; - using System.Collections.Generic; + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529787")] + [Fact(Skip = "529787")] + public async Task DoNotRemoveNecessaryCastWhichInCollectionInitializer1() + { + var source = + """ + using System; + using System.Collections.Generic; - class X : List - { - void Add(object x) + class X : List { - Console.WriteLine(1); - } + void Add(object x) + { + Console.WriteLine(1); + } - void Add(string x) - { - Console.WriteLine(2); - } + void Add(string x) + { + Console.WriteLine(2); + } - static void Main() - { - var z = new X { [|(object)""|] }; + static void Main() + { + var z = new X { [|(object)""|] }; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529787")] - [WpfFact(Skip = "529787")] - public async Task DoNotRemoveNecessaryCastWhichInCollectionInitializer2() - { - var source = - """ - using System; - using System.Collections.Generic; + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529787")] + [Fact(Skip = "529787")] + public async Task DoNotRemoveNecessaryCastWhichInCollectionInitializer2() + { + var source = + """ + using System; + using System.Collections.Generic; - class X : List - { - void Add(object x) + class X : List { - Console.WriteLine(1); - } + void Add(object x) + { + Console.WriteLine(1); + } - void Add(string x) - { - Console.WriteLine(2); - } + void Add(string x) + { + Console.WriteLine(2); + } - static void Main() - { - X z = new X { [|(object)""|] }; + static void Main() + { + X z = new X { [|(object)""|] }; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545607")] - public async Task RemoveUnneededCastInArrayInitializer() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class X - { - static void Goo() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545607")] + public async Task RemoveUnneededCastInArrayInitializer() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class X { - string x = ""; - var s = new object[] { [|(object)|]x }; + static void Goo() + { + string x = ""; + var s = new object[] { [|(object)|]x }; + } } - } - """, - """ - class X - { - static void Goo() + """, + """ + class X { - string x = ""; - var s = new object[] { x }; + static void Goo() + { + string x = ""; + var s = new object[] { x }; + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545616")] - public async Task RemoveUnneededCastWithOverloadedBinaryOperator() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - class MyAction - { - static void Goo() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545616")] + public async Task RemoveUnneededCastWithOverloadedBinaryOperator() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + class MyAction { - MyAction x = null; - var y = x + [|(Action)|]delegate { }; - } + static void Goo() + { + MyAction x = null; + var y = x + [|(Action)|]delegate { }; + } - public static MyAction operator +(MyAction x, Action y) - { - throw new NotImplementedException(); + public static MyAction operator +(MyAction x, Action y) + { + throw new NotImplementedException(); + } } - } - """, + """, - """ - using System; - class MyAction - { - static void Goo() + """ + using System; + class MyAction { - MyAction x = null; - var y = x + delegate { }; - } + static void Goo() + { + MyAction x = null; + var y = x + delegate { }; + } - public static MyAction operator +(MyAction x, Action y) - { - throw new NotImplementedException(); + public static MyAction operator +(MyAction x, Action y) + { + throw new NotImplementedException(); + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545616")] - public async Task DoNotRemoveCastFromLambdaToDelegateWithVar1() - { - var source = """ - using System; - class MyAction - { - static void Goo() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545616")] + public async Task DoNotRemoveCastFromLambdaToDelegateWithVar1() + { + var source = """ + using System; + class MyAction { - var y = (Action)(() => {}); + static void Goo() + { + var y = (Action)(() => {}); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545616")] - public async Task DoRemoveCastFromLambdaToDelegateWithTypedVariable() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - class MyAction - { - static void Goo() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545616")] + public async Task DoRemoveCastFromLambdaToDelegateWithTypedVariable() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + class MyAction { - Action y = [|(Action)|](() => { }); + static void Goo() + { + Action y = [|(Action)|](() => { }); + } } - } - """, - """ - using System; - class MyAction - { - static void Goo() + """, + """ + using System; + class MyAction { - Action y = () => { }; + static void Goo() + { + Action y = () => { }; + } } - } - """); - } - - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545822")] - public async Task RemoveUnnecessaryCastShouldInsertWhitespaceWhereNeededToKeepCorrectParsing() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + """); + } - class Program - { - static void Goo() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545822")] + public async Task RemoveUnnecessaryCastShouldInsertWhitespaceWhereNeededToKeepCorrectParsing() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + + class Program { - Action a = null; - var x = [|(Action)|](Goo)==a; + static void Goo() + { + Action a = null; + var x = [|(Action)|](Goo)==a; + } } - } - """, + """, - """ - using System; + """ + using System; - class Program - { - static void Goo() + class Program { - Action a = null; - var x = (Goo) == a; + static void Goo() + { + Action a = null; + var x = (Goo) == a; + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545560")] - public async Task DoNotRemoveNecessaryCastWithExplicitUserDefinedConversion() - { - var source = - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545560")] + public async Task DoNotRemoveNecessaryCastWithExplicitUserDefinedConversion() + { + var source = + """ + using System; - class A - { - public static explicit operator long(A x) + class A { - return 1; - } + public static explicit operator long(A x) + { + return 1; + } - public static implicit operator int(A x) - { - return 2; - } + public static implicit operator int(A x) + { + return 2; + } - static void Main() - { - var a = new A(); - long x = (long)a; - long y = a; - Console.WriteLine(x); // 1 - Console.WriteLine(y); // 2 + static void Main() + { + var a = new A(); + long x = (long)a; + long y = a; + Console.WriteLine(x); // 1 + Console.WriteLine(y); // 2 + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545608")] - public async Task DoNotRemoveNecessaryCastWithImplicitUserDefinedConversion() - { - var source = - """ - class X - { - static void Goo() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545608")] + public async Task DoNotRemoveNecessaryCastWithImplicitUserDefinedConversion() + { + var source = + """ + class X { - X x = null; - object y = (string)x; - } + static void Goo() + { + X x = null; + object y = (string)x; + } - public static implicit operator string(X x) - { - return "; + public static implicit operator string(X x) + { + return "; + } } - } - """; - - await VerifyCS.VerifyCodeFixAsync( - source, - [ - // /0/Test0.cs(11,16): error CS1010: Newline in constant - DiagnosticResult.CompilerError("CS1010").WithSpan(11, 16, 11, 16), - // /0/Test0.cs(11,18): error CS1002: ; expected - DiagnosticResult.CompilerError("CS1002").WithSpan(11, 18, 11, 18), - ], - source); - } - - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545941")] - public async Task DoNotRemoveNecessaryCastWithImplicitConversionInThrow() - { - // The cast below can't be removed because the throw statement expects - // an expression of type Exception -- not an expression convertible to - // Exception. + """; + + await VerifyCS.VerifyCodeFixAsync( + source, + [ + // /0/Test0.cs(11,16): error CS1010: Newline in constant + DiagnosticResult.CompilerError("CS1010").WithSpan(11, 16, 11, 16), + // /0/Test0.cs(11,18): error CS1002: ; expected + DiagnosticResult.CompilerError("CS1002").WithSpan(11, 18, 11, 18), + ], + source); + } + + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545941")] + public async Task DoNotRemoveNecessaryCastWithImplicitConversionInThrow() + { + // The cast below can't be removed because the throw statement expects + // an expression of type Exception -- not an expression convertible to + // Exception. - var source = - """ - using System; + var source = + """ + using System; - class E - { - public static implicit operator Exception(E e) + class E { - return new Exception(); - } + public static implicit operator Exception(E e) + { + return new Exception(); + } - static void Main() - { - throw (Exception)new E(); + static void Main() + { + throw (Exception)new E(); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545981")] - public async Task DoNotRemoveNecessaryCastInThrow() - { - // The cast below can't be removed because the throw statement expects - // an expression of type Exception -- not an expression convertible to - // Exception. + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545981")] + public async Task DoNotRemoveNecessaryCastInThrow() + { + // The cast below can't be removed because the throw statement expects + // an expression of type Exception -- not an expression convertible to + // Exception. - var source = - """ - using System; + var source = + """ + using System; - class C - { - static void Main() + class C { - object ex = new Exception(); - throw (Exception)ex; + static void Main() + { + object ex = new Exception(); + throw (Exception)ex; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545941")] - public async Task RemoveUnnecessaryCastInThrow() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545941")] + public async Task RemoveUnnecessaryCastInThrow() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - class E - { - static void Main() + class E { - throw [|(Exception)|]new Exception(); + static void Main() + { + throw [|(Exception)|]new Exception(); + } } - } - """, + """, - """ - using System; + """ + using System; - class E - { - static void Main() + class E { - throw new Exception(); + static void Main() + { + throw new Exception(); + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545945")] - public async Task DoNotRemoveNecessaryDowncast() - { - var source = - """ - class C - { - void Goo(object y) + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545945")] + public async Task DoNotRemoveNecessaryDowncast() + { + var source = + """ + class C { - int x = (int)y; + void Goo(object y) + { + int x = (int)y; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545591")] - public async Task DoNotRemoveNecessaryCastWithinLambda() - { - var source = - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545591")] + public async Task DoNotRemoveNecessaryCastWithinLambda() + { + var source = + """ + using System; - class Program - { - static void Main() + class Program { - Boo(x => Goo(x, y => (int)x), null); - } + static void Main() + { + Boo(x => Goo(x, y => (int)x), null); + } - static void Boo(Action x, object y) - { - Console.WriteLine(1); - } + static void Boo(Action x, object y) + { + Console.WriteLine(1); + } - static void Boo(Action x, string y) - { - Console.WriteLine(2); - } + static void Boo(Action x, string y) + { + Console.WriteLine(2); + } - static void Goo(int x, Func y) - { - } + static void Goo(int x, Func y) + { + } - static void Goo(string x, Func y) - { - } + static void Goo(string x, Func y) + { + } - static void Goo(string x, Func y) - { + static void Goo(string x, Func y) + { + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545606")] - public async Task DoNotRemoveNecessaryCastFromNullToTypeParameter() - { - var source = - """ - class X - { - static void Goo() where T : class, S + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545606")] + public async Task DoNotRemoveNecessaryCastFromNullToTypeParameter() + { + var source = + """ + class X { - S y = (T)null; + static void Goo() where T : class, S + { + S y = (T)null; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545744")] - public async Task DoNotRemoveNecessaryCastInImplicitlyTypedArray() - { - var source = - """ - class X - { - static void Goo() - { - string x = "; - var s = new[] { (object)x }; - s[0] = 1; - } - } - """; - - await VerifyCS.VerifyCodeFixAsync( - source, - [ - // /0/Test0.cs(5,20): error CS1010: Newline in constant - DiagnosticResult.CompilerError("CS1010").WithSpan(5, 20, 5, 20), - // /0/Test0.cs(5,22): error CS1002: ; expected - DiagnosticResult.CompilerError("CS1002").WithSpan(5, 22, 5, 22), - ], - source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545750")] - public async Task RemoveUnnecessaryCastToBaseType() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class X - { - static void Main() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545744")] + public async Task DoNotRemoveNecessaryCastInImplicitlyTypedArray() + { + var source = + """ + class X { - var s = ([|(object)|]new X()).ToString(); + static void Goo() + { + string x = "; + var s = new[] { (object)x }; + s[0] = 1; + } } - - public override string ToString() + """; + + await VerifyCS.VerifyCodeFixAsync( + source, + [ + // /0/Test0.cs(5,20): error CS1010: Newline in constant + DiagnosticResult.CompilerError("CS1010").WithSpan(5, 20, 5, 20), + // /0/Test0.cs(5,22): error CS1002: ; expected + DiagnosticResult.CompilerError("CS1002").WithSpan(5, 22, 5, 22), + ], + source); + } + + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545750")] + public async Task RemoveUnnecessaryCastToBaseType() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class X { - return ""; + static void Main() + { + var s = ([|(object)|]new X()).ToString(); + } + + public override string ToString() + { + return ""; + } } - } - """, - """ - class X - { - static void Main() + """, + """ + class X { - var s = new X().ToString(); - } + static void Main() + { + var s = new X().ToString(); + } - public override string ToString() - { - return ""; + public override string ToString() + { + return ""; + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545855")] - public async Task RemoveUnnecessaryLambdaToDelegateCast() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - using System.Collections.Generic; - using System.Reflection; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545855")] + public async Task RemoveUnnecessaryLambdaToDelegateCast() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + using System.Collections.Generic; + using System.Reflection; - static class Program - { - static void Main() + static class Program { - FieldInfo[] fields = typeof(Exception).GetFields(); - Console.WriteLine(fields.Any([|(Func)|](field => field.IsStatic))); - } + static void Main() + { + FieldInfo[] fields = typeof(Exception).GetFields(); + Console.WriteLine(fields.Any([|(Func)|](field => field.IsStatic))); + } - static bool Any(this IEnumerable s, Func predicate) - { - return false; + static bool Any(this IEnumerable s, Func predicate) + { + return false; + } + + static bool Any(this ICollection s, Func predicate) + { + return true; + } } + """, - static bool Any(this ICollection s, Func predicate) + """ + using System; + using System.Collections.Generic; + using System.Reflection; + + static class Program { - return true; + static void Main() + { + FieldInfo[] fields = typeof(Exception).GetFields(); + Console.WriteLine(fields.Any(field => field.IsStatic)); + } + + static bool Any(this IEnumerable s, Func predicate) + { + return false; + } + + static bool Any(this ICollection s, Func predicate) + { + return true; + } } - } - """, + """); + } - """ - using System; - using System.Collections.Generic; - using System.Reflection; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529816")] + public async Task RemoveUnnecessaryCastInQueryExpression() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - static class Program - { - static void Main() + class A { - FieldInfo[] fields = typeof(Exception).GetFields(); - Console.WriteLine(fields.Any(field => field.IsStatic)); + int Select(Func x) { return 1; } + + static void Main() + { + Console.WriteLine(from y in new A() select [|(long)|]0); + } } + """, - static bool Any(this IEnumerable s, Func predicate) + """ + using System; + + class A { - return false; + int Select(Func x) { return 1; } + + static void Main() + { + Console.WriteLine(from y in new A() select 0); + } } + """); + } + + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529816")] + public async Task DoNotRemoveNecessaryCastInQueryExpression() + { + var source = + """ + using System; - static bool Any(this ICollection s, Func predicate) + class A { - return true; + int Select(Func x) + { + return 1; + } + + int Select(Func x) + { + return 2; + } + + static void Main() + { + Console.WriteLine(from y in new A() + select (long)0); + } } - } - """); - } + """; - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529816")] - public async Task RemoveUnnecessaryCastInQueryExpression() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - class A - { - int Select(Func x) { return 1; } + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545848")] + public async Task DoNotRemoveNecessaryCastInConstructorInitializer() + { + var source = + """ + using System; - static void Main() + class C { - Console.WriteLine(from y in new A() select [|(long)|]0); - } - } - """, + static void Goo(int x, Func y) + { + } + + static void Goo(string x, Func y) + { + } - """ - using System; + C(Action x, object y) + { + Console.WriteLine(1); + } - class A - { - int Select(Func x) { return 1; } + C(Action x, string y) + { + Console.WriteLine(2); + } - static void Main() - { - Console.WriteLine(from y in new A() select 0); + C() : this(x => Goo(x, y => (int)x), null) + { + } + + static void Main() + { + new C(); + } } - } - """); - } + """; - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529816")] - public async Task DoNotRemoveNecessaryCastInQueryExpression() - { - var source = - """ - using System; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - class A - { - int Select(Func x) + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529831")] + public async Task DoNotRemoveNecessaryCastFromTypeParameterToInterface() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + + interface IIncrementable { - return 1; + int Value { get; } + + void Increment(); } - int Select(Func x) + struct S : IIncrementable { - return 2; + public int Value { get; private set; } + + public void Increment() + { + Value++; + } } - static void Main() + class C : IIncrementable { - Console.WriteLine(from y in new A() - select (long)0); + public int Value { get; private set; } + + public void Increment() + { + Value++; + } } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + static class Program + { + static void Main() + { + Goo(new S(), new C()); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545848")] - public async Task DoNotRemoveNecessaryCastInConstructorInitializer() - { - var source = - """ - using System; + static void Goo(TAny x, TClass y) + where TAny : IIncrementable + where TClass : class, IIncrementable + { + ((IIncrementable)x).Increment(); // False Unnecessary Cast + ([|(IIncrementable)|]y).Increment(); // Unnecessary Cast - OK - class C - { - static void Goo(int x, Func y) - { + Console.WriteLine(x.Value); + Console.WriteLine(y.Value); + } } + """, + """ + using System; - static void Goo(string x, Func y) + interface IIncrementable { - } + int Value { get; } - C(Action x, object y) - { - Console.WriteLine(1); + void Increment(); } - C(Action x, string y) + struct S : IIncrementable { - Console.WriteLine(2); - } + public int Value { get; private set; } - C() : this(x => Goo(x, y => (int)x), null) - { + public void Increment() + { + Value++; + } } - static void Main() + class C : IIncrementable { - new C(); + public int Value { get; private set; } + + public void Increment() + { + Value++; + } } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529831")] - public async Task DoNotRemoveNecessaryCastFromTypeParameterToInterface() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - - interface IIncrementable - { - int Value { get; } - - void Increment(); - } + static class Program + { + static void Main() + { + Goo(new S(), new C()); + } - struct S : IIncrementable - { - public int Value { get; private set; } + static void Goo(TAny x, TClass y) + where TAny : IIncrementable + where TClass : class, IIncrementable + { + ((IIncrementable)x).Increment(); // False Unnecessary Cast + y.Increment(); // Unnecessary Cast - OK - public void Increment() - { - Value++; + Console.WriteLine(x.Value); + Console.WriteLine(y.Value); + } } - } + """); + } - class C : IIncrementable - { - public int Value { get; private set; } + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529831")] + public async Task RemoveUnnecessaryCastFromTypeParameterToInterface() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - public void Increment() + interface IIncrementable { - Value++; + int Value { get; } + void Increment(); } - } - static class Program - { - static void Main() + struct S : IIncrementable { - Goo(new S(), new C()); + public int Value { get; private set; } + public void Increment() { Value++; } } - static void Goo(TAny x, TClass y) - where TAny : IIncrementable - where TClass : class, IIncrementable + class C: IIncrementable { - ((IIncrementable)x).Increment(); // False Unnecessary Cast - ([|(IIncrementable)|]y).Increment(); // Unnecessary Cast - OK - - Console.WriteLine(x.Value); - Console.WriteLine(y.Value); + public int Value { get; private set; } + public void Increment() { Value++; } } - } - """, - """ - using System; - - interface IIncrementable - { - int Value { get; } - void Increment(); - } - - struct S : IIncrementable - { - public int Value { get; private set; } - - public void Increment() + static class Program { - Value++; - } - } + static void Main() + { + Goo(new S(), new C()); + } - class C : IIncrementable - { - public int Value { get; private set; } + static void Goo(TAny x, TClass y) + where TAny : IIncrementable + where TClass : class, IIncrementable + { + ((IIncrementable)x).Increment(); // False Unnecessary Cast + ([|(IIncrementable)|]y).Increment(); // Unnecessary Cast - OK - public void Increment() - { - Value++; + Console.WriteLine(x.Value); + Console.WriteLine(y.Value); + } } - } + """, + """ + using System; - static class Program - { - static void Main() + interface IIncrementable { - Goo(new S(), new C()); + int Value { get; } + void Increment(); } - static void Goo(TAny x, TClass y) - where TAny : IIncrementable - where TClass : class, IIncrementable + struct S : IIncrementable { - ((IIncrementable)x).Increment(); // False Unnecessary Cast - y.Increment(); // Unnecessary Cast - OK - - Console.WriteLine(x.Value); - Console.WriteLine(y.Value); + public int Value { get; private set; } + public void Increment() { Value++; } } - } - """); - } - - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529831")] - public async Task RemoveUnnecessaryCastFromTypeParameterToInterface() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - - interface IIncrementable - { - int Value { get; } - void Increment(); - } - struct S : IIncrementable - { - public int Value { get; private set; } - public void Increment() { Value++; } - } - - class C: IIncrementable - { - public int Value { get; private set; } - public void Increment() { Value++; } - } - - static class Program - { - static void Main() + class C: IIncrementable { - Goo(new S(), new C()); + public int Value { get; private set; } + public void Increment() { Value++; } } - static void Goo(TAny x, TClass y) - where TAny : IIncrementable - where TClass : class, IIncrementable + static class Program { - ((IIncrementable)x).Increment(); // False Unnecessary Cast - ([|(IIncrementable)|]y).Increment(); // Unnecessary Cast - OK - - Console.WriteLine(x.Value); - Console.WriteLine(y.Value); - } - } - """, - """ - using System; - - interface IIncrementable - { - int Value { get; } - void Increment(); - } - - struct S : IIncrementable - { - public int Value { get; private set; } - public void Increment() { Value++; } - } + static void Main() + { + Goo(new S(), new C()); + } - class C: IIncrementable - { - public int Value { get; private set; } - public void Increment() { Value++; } - } + static void Goo(TAny x, TClass y) + where TAny : IIncrementable + where TClass : class, IIncrementable + { + ((IIncrementable)x).Increment(); // False Unnecessary Cast + y.Increment(); // Unnecessary Cast - OK - static class Program - { - static void Main() - { - Goo(new S(), new C()); + Console.WriteLine(x.Value); + Console.WriteLine(y.Value); + } } + """); + } + + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545877")] + public async Task DoNotCrashOnIncompleteMethodDeclaration() + { + // This test has intentional syntax errors + var source = + """ + using System; - static void Goo(TAny x, TClass y) - where TAny : IIncrementable - where TClass : class, IIncrementable + class A { - ((IIncrementable)x).Increment(); // False Unnecessary Cast - y.Increment(); // Unnecessary Cast - OK + static void Main() + { + byte{|CS1001:|}{|CS1002:|} + {|CS0411:Goo|}(x => 1, (byte)1); + } - Console.WriteLine(x.Value); - Console.WriteLine(y.Value); + static void Goo(T x, {|CS1001:{|CS1031:)|}|} + { + } } - } - """); - } + """; - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545877")] - public async Task DoNotCrashOnIncompleteMethodDeclaration() - { - // This test has intentional syntax errors - var source = - """ - using System; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - class A - { - static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/46423")] + public async Task RemoveUnneededTargetTypedCast() + { + await VerifyCS.VerifyCodeFixAsync(""" + class Other { - byte{|CS1001:|}{|CS1002:|} - {|CS0411:Goo|}(x => 1, (byte)1); - } + public short GetScopeIdForTelemetry(FixAllScope scope) + => [|(short)|](scope switch + { + FixAllScope.Document => 1, + FixAllScope.Project => 2, + FixAllScope.Solution => 3, + _ => 4, + }); - static void Goo(T x, {|CS1001:{|CS1031:)|}|} - { + public enum FixAllScope + { + Document, + Project, + Solution, + Other + } } - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } + """, + """ + class Other + { + public short GetScopeIdForTelemetry(FixAllScope scope) + => scope switch + { + FixAllScope.Document => 1, + FixAllScope.Project => 2, + FixAllScope.Solution => 3, + _ => 4, + }; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/46423")] - public async Task RemoveUnneededTargetTypedCast() - { - await VerifyCS.VerifyCodeFixAsync(""" - class Other - { - public short GetScopeIdForTelemetry(FixAllScope scope) - => [|(short)|](scope switch - { - FixAllScope.Document => 1, - FixAllScope.Project => 2, - FixAllScope.Solution => 3, - _ => 4, - }); - - public enum FixAllScope - { - Document, - Project, - Solution, - Other - } - } - """, - """ - class Other - { - public short GetScopeIdForTelemetry(FixAllScope scope) - => scope switch + public enum FixAllScope { - FixAllScope.Document => 1, - FixAllScope.Project => 2, - FixAllScope.Solution => 3, - _ => 4, - }; - - public enum FixAllScope - { - Document, - Project, - Solution, - Other + Document, + Project, + Solution, + Other + } } - } - """ + """ ); - } + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545777")] - public async Task DoNotRemoveImportantTrailingTrivia() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class Program - { - static void Main() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545777")] + public async Task DoNotRemoveImportantTrailingTrivia() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class Program { - long x = - #if true - [|(long)|] // Remove Unnecessary Cast - #endif - 1; + static void Main() + { + long x = + #if true + [|(long)|] // Remove Unnecessary Cast + #endif + 1; + } } - } - """, + """, - """ - class Program - { - static void Main() + """ + class Program { - long x = - #if true - // Remove Unnecessary Cast - #endif - 1; + static void Main() + { + long x = + #if true + // Remove Unnecessary Cast + #endif + 1; + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529791")] - public async Task RemoveUnnecessaryCastToNullable1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class X - { - static void Goo() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529791")] + public async Task RemoveUnnecessaryCastToNullable1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class X { - object x = [|(string)|]null; - object y = [|(int?)|]null; + static void Goo() + { + object x = [|(string)|]null; + object y = [|(int?)|]null; + } } - } - """, + """, - """ - class X - { - static void Goo() + """ + class X { - object x = null; - object y = null; + static void Goo() + { + object x = null; + object y = null; + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545842")] - public async Task RemoveUnnecessaryCastToNullable2() - { - await VerifyCS.VerifyCodeFixAsync( - """ - static class C - { - static void Main() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545842")] + public async Task RemoveUnnecessaryCastToNullable2() + { + await VerifyCS.VerifyCodeFixAsync( + """ + static class C { - int? x = 1; - long y = 2; - long? z = x + [|(long?)|] y; + static void Main() + { + int? x = 1; + long y = 2; + long? z = x + [|(long?)|] y; + } } - } - """, + """, - """ - static class C - { - static void Main() + """ + static class C { - int? x = 1; - long y = 2; - long? z = x + y; + static void Main() + { + int? x = 1; + long y = 2; + long? z = x + y; + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545850")] - public async Task RemoveSurroundingParentheses() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class Program - { - static void Main() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545850")] + public async Task RemoveSurroundingParentheses() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class Program { - int x = 1; - ([|(int)|]x).ToString(); + static void Main() + { + int x = 1; + ([|(int)|]x).ToString(); + } } - } - """, + """, - """ - class Program - { - static void Main() + """ + class Program { - int x = 1; - x.ToString(); + static void Main() + { + int x = 1; + x.ToString(); + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529846")] - public async Task DoNotRemoveNecessaryCastFromTypeParameterToObject() - { - var source = - """ - class C - { - static void Goo(T x, object y) + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529846")] + public async Task DoNotRemoveNecessaryCastFromTypeParameterToObject() + { + var source = + """ + class C { - if ((object)x == y) + static void Goo(T x, object y) { + if ((object)x == y) + { + } } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545858")] - public async Task DoNotRemoveNecessaryCastFromDelegateTypeToMulticastDelegate() - { - var source = - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545858")] + public async Task DoNotRemoveNecessaryCastFromDelegateTypeToMulticastDelegate() + { + var source = + """ + using System; - class C - { - static void Main() + class C { - Action x = Console.WriteLine; - Action y = Console.WriteLine; - Console.WriteLine((MulticastDelegate)x == y); + static void Main() + { + Action x = Console.WriteLine; + Action y = Console.WriteLine; + Console.WriteLine((MulticastDelegate)x == y); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545857")] - public async Task DoNotRemoveNecessaryCastInSizeOfArrayCreationExpression1() - { - // The cast below can't be removed because it would result in the implicit - // conversion to int being called instead. + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545857")] + public async Task DoNotRemoveNecessaryCastInSizeOfArrayCreationExpression1() + { + // The cast below can't be removed because it would result in the implicit + // conversion to int being called instead. - var source = - """ - using System; + var source = + """ + using System; - class C - { - static void Main() + class C { - Console.WriteLine(new int[(long)default(C)].Length); - } + static void Main() + { + Console.WriteLine(new int[(long)default(C)].Length); + } - public static implicit operator long(C x) - { - return 1; - } + public static implicit operator long(C x) + { + return 1; + } - public static implicit operator int(C x) - { - return 2; + public static implicit operator int(C x) + { + return 2; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545980")] - public async Task DoNotRemoveNecessaryCastInSizeOfArrayCreationExpression2() - { - // Array bounds must be an int, so the cast below can't be removed. + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545980")] + public async Task DoNotRemoveNecessaryCastInSizeOfArrayCreationExpression2() + { + // Array bounds must be an int, so the cast below can't be removed. - var source = - """ - class C - { - static void Main() + var source = + """ + class C { - var a = new int[(int)decimal.Zero]; + static void Main() + { + var a = new int[(int)decimal.Zero]; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529842")] - public async Task DoNotRemoveNecessaryCastInTernaryExpression() - { - var source = - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529842")] + public async Task DoNotRemoveNecessaryCastInTernaryExpression() + { + var source = + """ + using System; - class X - { - public static implicit operator string(X x) + class X { - return x.ToString(); - } + public static implicit operator string(X x) + { + return x.ToString(); + } - static void Main() - { - bool b = true; - X x = new X(); - Console.WriteLine(b ? (string)null : x); + static void Main() + { + bool b = true; + X x = new X(); + Console.WriteLine(b ? (string)null : x); + } } - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } + """; - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545882"), WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/880752")] - public async Task RemoveCastInConstructorInitializer1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class C - { - C(int x) { } - C() : this([|(int)|]1) { } - } - """, + await VerifyCS.VerifyCodeFixAsync(source, source); + } - """ - class C - { - C(int x) { } - C() : this(1) { } - } - """); - } + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545882"), WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/880752")] + public async Task RemoveCastInConstructorInitializer1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class C + { + C(int x) { } + C() : this([|(int)|]1) { } + } + """, - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545958"), WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/880752")] - public async Task RemoveCastInConstructorInitializer2() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System.Collections; + """ + class C + { + C(int x) { } + C() : this(1) { } + } + """); + } - class C - { - C(int x) { } - C(object x) { } - C() : this([|(IEnumerable)|]"") { } - } - """, + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545958"), WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/880752")] + public async Task RemoveCastInConstructorInitializer2() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System.Collections; - """ - using System.Collections; + class C + { + C(int x) { } + C(object x) { } + C() : this([|(IEnumerable)|]"") { } + } + """, - class C - { - C(int x) { } - C(object x) { } - C() : this("") { } - } - """); - } + """ + using System.Collections; - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545957")] - public async Task DoNotRemoveCastInConstructorInitializer3() - { - var source = - """ - class C - { - C(int x) + class C { + C(int x) { } + C(object x) { } + C() : this("") { } } + """); + } - C() : this((long)1) + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545957")] + public async Task DoNotRemoveCastInConstructorInitializer3() + { + var source = + """ + class C { + C(int x) + { + } + + C() : this((long)1) + { + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync( - source, - // /0/Test0.cs(7,16): error CS1503: Argument 1: cannot convert from 'long' to 'int' - DiagnosticResult.CompilerError("CS1503").WithSpan(7, 16, 7, 23).WithArguments("1", "long", "int"), - source); - } + await VerifyCS.VerifyCodeFixAsync( + source, + // /0/Test0.cs(7,16): error CS1503: Argument 1: cannot convert from 'long' to 'int' + DiagnosticResult.CompilerError("CS1503").WithSpan(7, 16, 7, 23).WithArguments("1", "long", "int"), + source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545842")] - public async Task RemoveCastToNullableInArithmeticExpression() - { - await VerifyCS.VerifyCodeFixAsync( - """ - static class C - { - static void Main() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545842")] + public async Task RemoveCastToNullableInArithmeticExpression() + { + await VerifyCS.VerifyCodeFixAsync( + """ + static class C { - int? x = 1; - long y = 2; - long? z = x + [|(long?)|]y; + static void Main() + { + int? x = 1; + long y = 2; + long? z = x + [|(long?)|]y; + } } - } - """, + """, - """ - static class C - { - static void Main() + """ + static class C { - int? x = 1; - long y = 2; - long? z = x + y; + static void Main() + { + int? x = 1; + long y = 2; + long? z = x + y; + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545942")] - public async Task DoNotRemoveCastFromValueTypeToObjectInReferenceEquality() - { - // Note: The cast below can't be removed because it would result in an - // illegal reference equality test between object and a value type. + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545942")] + public async Task DoNotRemoveCastFromValueTypeToObjectInReferenceEquality() + { + // Note: The cast below can't be removed because it would result in an + // illegal reference equality test between object and a value type. - var source = - """ - using System; + var source = + """ + using System; - class Program - { - static void Main() + class Program { - object x = 1; - Console.WriteLine(x == (object)1); + static void Main() + { + object x = 1; + Console.WriteLine(x == (object)1); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545962")] - public async Task DoNotRemoveCastWhenExpressionDoesntBind() - { - // Note: The cast below can't be removed because its expression doesn't bind. + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545962")] + public async Task DoNotRemoveCastWhenExpressionDoesntBind() + { + // Note: The cast below can't be removed because its expression doesn't bind. - var source = - """ - using System; + var source = + """ + using System; - class Program - { - static void Main() + class Program { - ((IDisposable){|CS0103:x|}).Dispose(); + static void Main() + { + ((IDisposable){|CS0103:x|}).Dispose(); + } } - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545944")] - public async Task DoNotRemoveNecessaryCastBeforePointerDereference1() - { - // Note: The cast below can't be removed because it would result in *null, - // which is illegal. + """; - var source = - """ - unsafe class C - { - int x = *(int*)null; - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545978")] - public async Task DoNotRemoveNecessaryCastBeforePointerDereference2() - { - // Note: The cast below can't be removed because it would result in dereferencing - // void*, which is illegal. + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545944")] + public async Task DoNotRemoveNecessaryCastBeforePointerDereference1() + { + // Note: The cast below can't be removed because it would result in *null, + // which is illegal. - var source = - """ - unsafe class C - { - static void Main() + var source = + """ + unsafe class C { - void* p = null; - int x = *(int*)p; + int x = *(int*)null; } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2987")] - [WorkItem("https://github.com/dotnet/roslyn/issues/2691")] - public async Task DoNotRemoveNecessaryCastBeforePointerDereference3() - { - // Conservatively disable cast simplifications for casts involving pointer conversions. - // https://github.com/dotnet/roslyn/issues/2987 tracks improving cast simplification for this scenario. + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545978")] + public async Task DoNotRemoveNecessaryCastBeforePointerDereference2() + { + // Note: The cast below can't be removed because it would result in dereferencing + // void*, which is illegal. - var source = - """ - class C - { - public unsafe float ReadSingle(byte* ptr) + var source = + """ + unsafe class C { - return *(float*)ptr; + static void Main() + { + void* p = null; + int x = *(int*)p; + } } - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } + """; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2987")] - [WorkItem("https://github.com/dotnet/roslyn/issues/2691")] - public async Task DoNotRemoveNumericCastInUncheckedExpression() - { - // Conservatively disable cast simplifications within explicit checked/unchecked expressions. - // https://github.com/dotnet/roslyn/issues/2987 tracks improving cast simplification for this scenario. + await VerifyCS.VerifyCodeFixAsync(source, source); + } - var source = - """ - class C - { - private unsafe readonly byte* _endPointer; - private unsafe byte* _currentPointer; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2987")] + [WorkItem("https://github.com/dotnet/roslyn/issues/2691")] + public async Task DoNotRemoveNecessaryCastBeforePointerDereference3() + { + // Conservatively disable cast simplifications for casts involving pointer conversions. + // https://github.com/dotnet/roslyn/issues/2987 tracks improving cast simplification for this scenario. - private unsafe void CheckBounds(int byteCount) + var source = + """ + class C { - if (unchecked((uint)byteCount) > (_endPointer - _currentPointer)) + public unsafe float ReadSingle(byte* ptr) { + return *(float*)ptr; } } - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } + """; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2987")] - [WorkItem("https://github.com/dotnet/roslyn/issues/2691")] - public async Task DoNotRemoveNumericCastInUncheckedStatement() - { - // Conservatively disable cast simplifications within explicit checked/unchecked statements. - // https://github.com/dotnet/roslyn/issues/2987 tracks improving cast simplification for this scenario. + await VerifyCS.VerifyCodeFixAsync(source, source); + } - var source = - """ - class C - { - private unsafe readonly byte* _endPointer; - private unsafe byte* _currentPointer; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2987")] + [WorkItem("https://github.com/dotnet/roslyn/issues/2691")] + public async Task DoNotRemoveNumericCastInUncheckedExpression() + { + // Conservatively disable cast simplifications within explicit checked/unchecked expressions. + // https://github.com/dotnet/roslyn/issues/2987 tracks improving cast simplification for this scenario. - private unsafe void CheckBounds(int byteCount) + var source = + """ + class C { - unchecked + private unsafe readonly byte* _endPointer; + private unsafe byte* _currentPointer; + + private unsafe void CheckBounds(int byteCount) { - if (((uint)byteCount) > (_endPointer - _currentPointer)) + if (unchecked((uint)byteCount) > (_endPointer - _currentPointer)) { } } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2987")] - [WorkItem("https://github.com/dotnet/roslyn/issues/2691")] - public async Task DoNotRemoveNumericCastInCheckedExpression() - { - // Conservatively disable cast simplifications within explicit checked/unchecked expressions. - // https://github.com/dotnet/roslyn/issues/2987 tracks improving cast simplification for this scenario. + await VerifyCS.VerifyCodeFixAsync(source, source); + } - var source = - """ - class C - { - private unsafe readonly byte* _endPointer; - private unsafe byte* _currentPointer; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2987")] + [WorkItem("https://github.com/dotnet/roslyn/issues/2691")] + public async Task DoNotRemoveNumericCastInUncheckedStatement() + { + // Conservatively disable cast simplifications within explicit checked/unchecked statements. + // https://github.com/dotnet/roslyn/issues/2987 tracks improving cast simplification for this scenario. - private unsafe void CheckBounds(int byteCount) + var source = + """ + class C { - if (checked((uint)byteCount) > (_endPointer - _currentPointer)) + private unsafe readonly byte* _endPointer; + private unsafe byte* _currentPointer; + + private unsafe void CheckBounds(int byteCount) { + unchecked + { + if (((uint)byteCount) > (_endPointer - _currentPointer)) + { + } + } } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2987")] - [WorkItem("https://github.com/dotnet/roslyn/issues/2691")] - public async Task DoNotRemoveNumericCastInCheckedStatement() - { - // Conservatively disable cast simplifications within explicit checked/unchecked statements. - // https://github.com/dotnet/roslyn/issues/2987 tracks improving cast simplification for this scenario. + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2987")] + [WorkItem("https://github.com/dotnet/roslyn/issues/2691")] + public async Task DoNotRemoveNumericCastInCheckedExpression() + { + // Conservatively disable cast simplifications within explicit checked/unchecked expressions. + // https://github.com/dotnet/roslyn/issues/2987 tracks improving cast simplification for this scenario. - var source = - """ - class C - { - private unsafe readonly byte* _endPointer; - private unsafe byte* _currentPointer; + var source = + """ + class C + { + private unsafe readonly byte* _endPointer; + private unsafe byte* _currentPointer; + + private unsafe void CheckBounds(int byteCount) + { + if (checked((uint)byteCount) > (_endPointer - _currentPointer)) + { + } + } + } + """; + + await VerifyCS.VerifyCodeFixAsync(source, source); + } - private unsafe void CheckBounds(int byteCount) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2987")] + [WorkItem("https://github.com/dotnet/roslyn/issues/2691")] + public async Task DoNotRemoveNumericCastInCheckedStatement() + { + // Conservatively disable cast simplifications within explicit checked/unchecked statements. + // https://github.com/dotnet/roslyn/issues/2987 tracks improving cast simplification for this scenario. + + var source = + """ + class C { - checked + private unsafe readonly byte* _endPointer; + private unsafe byte* _currentPointer; + + private unsafe void CheckBounds(int byteCount) { - if (((uint)byteCount) > (_endPointer - _currentPointer)) + checked { + if (((uint)byteCount) > (_endPointer - _currentPointer)) + { + } } } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26640")] - public async Task DoNotRemoveCastToByteFromIntInConditionalExpression() - { - var source = """ - class C - { - object M1(bool b) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26640")] + public async Task DoNotRemoveCastToByteFromIntInConditionalExpression() + { + var source = """ + class C { - return b ? (byte)1 : (byte)0; + object M1(bool b) + { + return b ? (byte)1 : (byte)0; + } } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26640")] - public async Task RemoveCastToDoubleFromIntWithTwoInConditionalExpression() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class C - { - object M1(bool b) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26640")] + public async Task RemoveCastToDoubleFromIntWithTwoInConditionalExpression() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class C { - return b ? [|(double)|]1 : [|(double)|]0; + object M1(bool b) + { + return b ? [|(double)|]1 : [|(double)|]0; + } } - } - """, - """ - class C - { - object M1(bool b) + """, + """ + class C { - return b ? 1 : (double)0; + object M1(bool b) + { + return b ? 1 : (double)0; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26640")] - public async Task DoNotRemoveCastToDoubleFromIntInConditionalExpression() - { - var source = - """ - class C - { - object M1(bool b) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26640")] + public async Task DoNotRemoveCastToDoubleFromIntInConditionalExpression() + { + var source = + """ + class C { - return b ? 1 : (double)0; + object M1(bool b) + { + return b ? 1 : (double)0; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26640")] - public async Task DoNotRemoveCastToUIntFromCharInConditionalExpression() - { - var source = - """ - class C - { - object M1(bool b) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26640")] + public async Task DoNotRemoveCastToUIntFromCharInConditionalExpression() + { + var source = + """ + class C { - return b ? '1' : (uint)'0'; + object M1(bool b) + { + return b ? '1' : (uint)'0'; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26640")] - public async Task RemoveUnnecessaryNumericCastToSameTypeInConditionalExpression() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class C - { - object M1(bool b) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26640")] + public async Task RemoveUnnecessaryNumericCastToSameTypeInConditionalExpression() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class C { - return b ? [|(int)|]1 : 0; + object M1(bool b) + { + return b ? [|(int)|]1 : 0; + } } - } - """, - """ - class C - { - object M1(bool b) + """, + """ + class C { - return b ? 1 : 0; + object M1(bool b) + { + return b ? 1 : 0; + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545894")] - public async Task DoNotRemoveNecessaryCastInAttribute() - { - var source = - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545894")] + public async Task DoNotRemoveNecessaryCastInAttribute() + { + var source = + """ + using System; - [A((byte)0)] - class A : Attribute - { - public A(object x) + [A((byte)0)] + class A : Attribute { + public A(object x) + { + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545894")] - public async Task DoRemoveUnnecessaryCastInAttribute() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545894")] + public async Task DoRemoveUnnecessaryCastInAttribute() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - [A([|(int)|]0)] - class A : Attribute - { - public A(object x) + [A([|(int)|]0)] + class A : Attribute { + public A(object x) + { + } } - } - """, - """ - using System; + """, + """ + using System; - [A(0)] - class A : Attribute - { - public A(object x) + [A(0)] + class A : Attribute { + public A(object x) + { + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545894")] - public async Task DoNotRemoveImplicitConstantConversionToDifferentType() - { - var source = - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545894")] + public async Task DoNotRemoveImplicitConstantConversionToDifferentType() + { + var source = + """ + using System; - class A : Attribute - { - public A() + class A : Attribute { - object x = (byte)0; + public A() + { + object x = (byte)0; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545894")] - public async Task DoRemoveImplicitConstantConversionToSameType() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545894")] + public async Task DoRemoveImplicitConstantConversionToSameType() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - class A : Attribute - { - public A() + class A : Attribute { - object x = [|(int)|]0; + public A() + { + object x = [|(int)|]0; + } } - } - """, - """ - using System; + """, + """ + using System; - class A : Attribute - { - public A() + class A : Attribute { - object x = 0; + public A() + { + object x = 0; + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545894")] - public async Task DoNotRemoveNumericConversionBoxed() - { - var source = - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545894")] + public async Task DoNotRemoveNumericConversionBoxed() + { + var source = + """ + using System; - class A : Attribute - { - public A(int i) + class A : Attribute { - object x = (long)i; + public A(int i) + { + object x = (long)i; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545894")] - public async Task DoRemoveNumericConversionNotBoxed() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545894")] + public async Task DoRemoveNumericConversionNotBoxed() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - class A : Attribute - { - public A(int i) + class A : Attribute { - long x = [|(long)|]i; + public A(int i) + { + long x = [|(long)|]i; + } } - } - """, - """ - using System; + """, + """ + using System; - class A : Attribute - { - public A(int i) + class A : Attribute { - long x = i; + public A(int i) + { + long x = i; + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545894")] - public async Task DoRemoveNonConstantCastInAttribute() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545894")] + public async Task DoRemoveNonConstantCastInAttribute() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - [A({|CS0182:[|(IComparable)|]0|})] - class A : Attribute - { - public A(object x) + [A({|CS0182:[|(IComparable)|]0|})] + class A : Attribute { + public A(object x) + { + } } - } - """, - """ - using System; + """, + """ + using System; - [A(0)] - class A : Attribute - { - public A(object x) + [A(0)] + class A : Attribute { + public A(object x) + { + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/39042")] - public async Task DoNotRemoveNecessaryCastForImplicitNumericCastsThatLoseInformation() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/39042")] + public async Task DoNotRemoveNecessaryCastForImplicitNumericCastsThatLoseInformation() + { + var source = + """ + using System; - class A - { - public A(long x) + class A { - long y = (long)(double)x; + public A(long x) + { + long y = (long)(double)x; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - #region Interface Casts + #region Interface Casts - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545889")] - public async Task DoNotRemoveCastToInterfaceForUnsealedType() - { - // Note: The cast below can't be removed because X is not sealed. + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545889")] + public async Task DoNotRemoveCastToInterfaceForUnsealedType() + { + // Note: The cast below can't be removed because X is not sealed. - var source = - """ - using System; + var source = + """ + using System; - class X : IDisposable - { - static void Main() + class X : IDisposable { - X x = new Y(); - ((IDisposable)x).Dispose(); - } + static void Main() + { + X x = new Y(); + ((IDisposable)x).Dispose(); + } - public void Dispose() - { - Console.WriteLine("X.Dispose"); + public void Dispose() + { + Console.WriteLine("X.Dispose"); + } } - } - class Y : X, IDisposable - { - void IDisposable.Dispose() + class Y : X, IDisposable { - Console.WriteLine("Y.Dispose"); + void IDisposable.Dispose() + { + Console.WriteLine("Y.Dispose"); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545890")] - [WorkItem("https://github.com/dotnet/roslyn/issues/34326")] - public async Task DoRemoveCastToInterfaceForSealedType1() - { - await VerifyCS.VerifyCodeFixAsync(""" - using System; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - interface I - { - void Goo(int x = 0); - } + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545890")] + [WorkItem("https://github.com/dotnet/roslyn/issues/34326")] + public async Task DoRemoveCastToInterfaceForSealedType1() + { + await VerifyCS.VerifyCodeFixAsync(""" + using System; - sealed class C : I - { - public void Goo(int x = 0) + interface I { - Console.WriteLine(x); + void Goo(int x = 0); } - static void Main() + sealed class C : I { - ([|(I)|]new C()).Goo(); - } - } - """, - """ - using System; - - interface I - { - void Goo(int x = 0); - } + public void Goo(int x = 0) + { + Console.WriteLine(x); + } - sealed class C : I - { - public void Goo(int x = 0) - { - Console.WriteLine(x); + static void Main() + { + ([|(I)|]new C()).Goo(); + } } + """, + """ + using System; - static void Main() + interface I { - new C().Goo(); + void Goo(int x = 0); } - } - """); - } - - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545890")] - [WorkItem("https://github.com/dotnet/roslyn/issues/34326")] - public async Task DoRemoveCastToInterfaceForSealedType2() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - - interface I - { - string Goo { get; } - } - sealed class C : I - { - public string Goo + sealed class C : I { - get + public void Goo(int x = 0) + { + Console.WriteLine(x); + } + + static void Main() { - return "Nikov Rules"; + new C().Goo(); } } + """); + } + + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545890")] + [WorkItem("https://github.com/dotnet/roslyn/issues/34326")] + public async Task DoRemoveCastToInterfaceForSealedType2() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - static void Main() + interface I { - Console.WriteLine(([|(I)|]new C()).Goo); + string Goo { get; } } - } - """, - """ - using System; - - interface I - { - string Goo { get; } - } - sealed class C : I - { - public string Goo + sealed class C : I { - get + public string Goo + { + get + { + return "Nikov Rules"; + } + } + + static void Main() { - return "Nikov Rules"; + Console.WriteLine(([|(I)|]new C()).Goo); } } + """, + """ + using System; - static void Main() + interface I { - Console.WriteLine(new C().Goo); + string Goo { get; } } - } - """); - } - - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545890")] - [WorkItem("https://github.com/dotnet/roslyn/issues/34326")] - public async Task DoRemoveCastToInterfaceForSealedType3() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - interface I - { - string Goo { get; } - } - - sealed class C : I - { - public C Instance { get { return new C(); } } - - public string Goo + sealed class C : I { - get + public string Goo + { + get + { + return "Nikov Rules"; + } + } + + static void Main() { - return "Nikov Rules"; + Console.WriteLine(new C().Goo); } } + """); + } + + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545890")] + [WorkItem("https://github.com/dotnet/roslyn/issues/34326")] + public async Task DoRemoveCastToInterfaceForSealedType3() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - void Main() + interface I { - Console.WriteLine(([|(I)|]Instance).Goo); + string Goo { get; } } - } - """, - """ - using System; - interface I - { - string Goo { get; } - } + sealed class C : I + { + public C Instance { get { return new C(); } } - sealed class C : I - { - public C Instance { get { return new C(); } } + public string Goo + { + get + { + return "Nikov Rules"; + } + } - public string Goo - { - get + void Main() { - return "Nikov Rules"; + Console.WriteLine(([|(I)|]Instance).Goo); } } + """, + """ + using System; - void Main() + interface I { - Console.WriteLine(Instance.Goo); + string Goo { get; } } - } - """); - } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545890")] - public async Task DoNotRemoveCastToInterfaceForSealedType4() - { - var source = - """ - using System; + sealed class C : I + { + public C Instance { get { return new C(); } } - interface I - { - void Goo(int x = 0); - } + public string Goo + { + get + { + return "Nikov Rules"; + } + } - sealed class C : I - { - public void Goo(int x = 1) - { - Console.WriteLine(x); + void Main() + { + Console.WriteLine(Instance.Goo); + } } + """); + } + + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545890")] + public async Task DoNotRemoveCastToInterfaceForSealedType4() + { + var source = + """ + using System; - static void Main() + interface I { - ((I)new C()).Goo(); + void Goo(int x = 0); } - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545890")] - [WorkItem("https://github.com/dotnet/roslyn/issues/34326")] - public async Task DoRemoveCastToInterfaceForSealedTypeWhenParameterValuesDifferButExplicitValueIsProvided() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + sealed class C : I + { + public void Goo(int x = 1) + { + Console.WriteLine(x); + } - interface I - { - void Goo(int x = 0); - } + static void Main() + { + ((I)new C()).Goo(); + } + } + """; - sealed class C : I - { - public void Goo(int x = 1) + await VerifyCS.VerifyCodeFixAsync(source, source); + } + + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545890")] + [WorkItem("https://github.com/dotnet/roslyn/issues/34326")] + public async Task DoRemoveCastToInterfaceForSealedTypeWhenParameterValuesDifferButExplicitValueIsProvided() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + + interface I { - Console.WriteLine(x); + void Goo(int x = 0); } - static void Main() + sealed class C : I { - ([|(I)|]new C()).Goo(2); - } - } - """, - """ - using System; + public void Goo(int x = 1) + { + Console.WriteLine(x); + } - interface I - { - void Goo(int x = 0); - } + static void Main() + { + ([|(I)|]new C()).Goo(2); + } + } + """, + """ + using System; - sealed class C : I - { - public void Goo(int x = 1) + interface I { - Console.WriteLine(x); + void Goo(int x = 0); } - static void Main() + sealed class C : I { - new C().Goo(2); - } - } - """); - } + public void Goo(int x = 1) + { + Console.WriteLine(x); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545888")] - public async Task DoNotRemoveCastToInterfaceForSealedType6() - { - // Note: The cast below can't be removed (even though C is sealed) - // because the specified named arguments refer to parameters that - // appear at different positions in the member signatures. + static void Main() + { + new C().Goo(2); + } + } + """); + } - var source = - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545888")] + public async Task DoNotRemoveCastToInterfaceForSealedType6() + { + // Note: The cast below can't be removed (even though C is sealed) + // because the specified named arguments refer to parameters that + // appear at different positions in the member signatures. - interface I - { - void Goo(int x = 0, int y = 0); - } + var source = + """ + using System; - sealed class C : I - { - public void Goo(int y = 0, int x = 0) + interface I { - Console.WriteLine(x); + void Goo(int x = 0, int y = 0); } - static void Main() + sealed class C : I { - ((I)new C()).Goo(x: 1); - } - } - """; + public void Goo(int y = 0, int x = 0) + { + Console.WriteLine(x); + } - await VerifyCS.VerifyCodeFixAsync(source, source); - } + static void Main() + { + ((I)new C()).Goo(x: 1); + } + } + """; - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545888")] - public async Task DoRemoveCastToInterfaceWhenNoDefaultArgsPassedAndValuesAreTheSame() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - interface I - { - void Goo(int x = 0); - } + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545888")] + public async Task DoRemoveCastToInterfaceWhenNoDefaultArgsPassedAndValuesAreTheSame() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - sealed class C : I - { - public void Goo(int x = 0) + interface I { - Console.WriteLine(x); + void Goo(int x = 0); } - static void Main() + sealed class C : I { - ([|(I)|]new C()).Goo(); - } - } - """, - """ - using System; + public void Goo(int x = 0) + { + Console.WriteLine(x); + } - interface I - { - void Goo(int x = 0); - } + static void Main() + { + ([|(I)|]new C()).Goo(); + } + } + """, + """ + using System; - sealed class C : I - { - public void Goo(int x = 0) + interface I { - Console.WriteLine(x); + void Goo(int x = 0); } - static void Main() + sealed class C : I { - new C().Goo(); - } - } - """); - } + public void Goo(int x = 0) + { + Console.WriteLine(x); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545888")] - public async Task DoRemoveCastToInterfaceWhenDefaultArgPassedAndValuesAreDifferent() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + static void Main() + { + new C().Goo(); + } + } + """); + } - interface I - { - void Goo(int x = 0); - } + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545888")] + public async Task DoRemoveCastToInterfaceWhenDefaultArgPassedAndValuesAreDifferent() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - sealed class C : I - { - public void Goo(int x = 1) + interface I { - Console.WriteLine(x); + void Goo(int x = 0); } - static void Main() + sealed class C : I { - ([|(I)|]new C()).Goo(2); - } - } - """, - """ - using System; + public void Goo(int x = 1) + { + Console.WriteLine(x); + } - interface I - { - void Goo(int x = 0); - } + static void Main() + { + ([|(I)|]new C()).Goo(2); + } + } + """, + """ + using System; - sealed class C : I - { - public void Goo(int x = 1) + interface I { - Console.WriteLine(x); + void Goo(int x = 0); } - static void Main() + sealed class C : I { - new C().Goo(2); - } - } - """); - } + public void Goo(int x = 1) + { + Console.WriteLine(x); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545888")] - public async Task DoNotRemoveCastToInterfaceWhenNoDefaultArgsPassedAndValuesAreDifferent() - { - var source = """ - using System; + static void Main() + { + new C().Goo(2); + } + } + """); + } - interface I - { - void Goo(int x = 0); - } + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545888")] + public async Task DoNotRemoveCastToInterfaceWhenNoDefaultArgsPassedAndValuesAreDifferent() + { + var source = """ + using System; - sealed class C : I - { - public void Goo(int x = 1) + interface I { - Console.WriteLine(x); + void Goo(int x = 0); } - static void Main() + sealed class C : I { - ((I)new C()).Goo(); - } - } - """; + public void Goo(int x = 1) + { + Console.WriteLine(x); + } - await VerifyCS.VerifyCodeFixAsync(source, source); - } + static void Main() + { + ((I)new C()).Goo(); + } + } + """; - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545888")] - public async Task DoRemoveCastToInterfaceWhenNamesAreTheSameAndNoNameProvided() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - interface I - { - void Goo(int x); - } + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545888")] + public async Task DoRemoveCastToInterfaceWhenNamesAreTheSameAndNoNameProvided() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - sealed class C : I - { - public void Goo(int x) + interface I { - Console.WriteLine(x); + void Goo(int x); } - static void Main() + sealed class C : I { - ([|(I)|]new C()).Goo(0); - } - } - """, - """ - using System; + public void Goo(int x) + { + Console.WriteLine(x); + } - interface I - { - void Goo(int x); - } + static void Main() + { + ([|(I)|]new C()).Goo(0); + } + } + """, + """ + using System; - sealed class C : I - { - public void Goo(int x) + interface I { - Console.WriteLine(x); + void Goo(int x); } - static void Main() + sealed class C : I { - new C().Goo(0); - } - } - """); - } + public void Goo(int x) + { + Console.WriteLine(x); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545888")] - public async Task DoRemoveCastToInterfaceWhenNamesAreDifferentAndNoNameProvided() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + static void Main() + { + new C().Goo(0); + } + } + """); + } - interface I - { - void Goo(int x); - } + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545888")] + public async Task DoRemoveCastToInterfaceWhenNamesAreDifferentAndNoNameProvided() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - sealed class C : I - { - public void Goo(int y) + interface I { - Console.WriteLine(y); + void Goo(int x); } - static void Main() + sealed class C : I { - ([|(I)|]new C()).Goo(0); - } - } - """, - """ - using System; + public void Goo(int y) + { + Console.WriteLine(y); + } - interface I - { - void Goo(int x); - } + static void Main() + { + ([|(I)|]new C()).Goo(0); + } + } + """, + """ + using System; - sealed class C : I - { - public void Goo(int y) + interface I { - Console.WriteLine(y); + void Goo(int x); } - static void Main() + sealed class C : I { - new C().Goo(0); - } - } - """); - } + public void Goo(int y) + { + Console.WriteLine(y); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545888")] - public async Task DoNotRemoveCastToInterfaceWhenNamesAreDifferentAndNameProvided() - { - var source = """ - using System; + static void Main() + { + new C().Goo(0); + } + } + """); + } - interface I - { - void Goo(int x); - } + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545888")] + public async Task DoNotRemoveCastToInterfaceWhenNamesAreDifferentAndNameProvided() + { + var source = """ + using System; - sealed class C : I - { - public void Goo(int y) + interface I { - Console.WriteLine(y); + void Goo(int x); } - static void Main() + sealed class C : I { - ((I)new C()).Goo(x: 0); + public void Goo(int y) + { + Console.WriteLine(y); + } + + static void Main() + { + ((I)new C()).Goo(x: 0); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545888")] - [WorkItem("https://github.com/dotnet/roslyn/issues/34326")] - public async Task DoNotRemoveCastToInterfaceForSealedType7() - { - var source = - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545888")] + [WorkItem("https://github.com/dotnet/roslyn/issues/34326")] + public async Task DoNotRemoveCastToInterfaceForSealedType7() + { + var source = + """ + using System; - interface I - { - int this[int x = 0, int y = 0] { get; } - } + interface I + { + int this[int x = 0, int y = 0] { get; } + } - sealed class C : I - { - public int this[int x = 0, int y = 0] + sealed class C : I { - get + public int this[int x = 0, int y = 0] { - return x * 2; + get + { + return x * 2; + } } - } - static void Main() - { - Console.WriteLine(((I)new C())[x: 1]); + static void Main() + { + Console.WriteLine(((I)new C())[x: 1]); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545888")] - public async Task DoNotRemoveCastToInterfaceForSealedType8() - { - // Note: The cast below can't be removed (even though C is sealed) - // because the specified named arguments refer to parameters that - // appear at different positions in the member signatures. - - var source = - """ - using System; - - interface I - { - int this[int x = 0, int y = 0] { get; } - } - - sealed class C : I - { - public int this(int y = 0, int x = 0) - { - get - { - return x * 2; - } - } - - static void Main() - { - Console.WriteLine(((I)new C())[x: 1]); - } - } - """; - - await VerifyCS.VerifyCodeFixAsync( - source, - [ - // /0/Test0.cs(8,18): error CS0535: 'C' does not implement interface member 'I.this[int, int]' - DiagnosticResult.CompilerError("CS0535").WithSpan(8, 18, 8, 19).WithArguments("C", "I.this[int, int]"), - // /0/Test0.cs(10,16): error CS0548: 'C.this[(int y, ?), int]': property or indexer must have at least one accessor - DiagnosticResult.CompilerError("CS0548").WithSpan(10, 16, 10, 20).WithArguments("C.this[(int y, ?), int]"), - // /0/Test0.cs(10,20): error CS1003: Syntax error, '[' expected - DiagnosticResult.CompilerError("CS1003").WithSpan(10, 20, 10, 21).WithArguments("["), - // /0/Test0.cs(10,27): error CS1750: A value of type 'int' cannot be used as a default parameter because there are no standard conversions to type '(int y, ?)' - DiagnosticResult.CompilerError("CS1750").WithSpan(10, 27, 10, 27).WithArguments("int", "(int y, ?)"), - // /0/Test0.cs(10,27): error CS1001: Identifier expected - DiagnosticResult.CompilerError("CS1001").WithSpan(10, 27, 10, 28), - // /0/Test0.cs(10,27): error CS1026: ) expected - DiagnosticResult.CompilerError("CS1026").WithSpan(10, 27, 10, 28), - // /0/Test0.cs(10,27): error CS8124: Tuple must contain at least two elements. - DiagnosticResult.CompilerError("CS8124").WithSpan(10, 27, 10, 28), - // /0/Test0.cs(10,41): error CS1003: Syntax error, ']' expected - DiagnosticResult.CompilerError("CS1003").WithSpan(10, 41, 10, 42).WithArguments("]"), - // /0/Test0.cs(10,41): error CS1014: A get or set accessor expected - DiagnosticResult.CompilerError("CS1014").WithSpan(10, 41, 10, 42), - // /0/Test0.cs(10,41): error CS1514: { expected - DiagnosticResult.CompilerError("CS1514").WithSpan(10, 41, 10, 42), - // /0/Test0.cs(10,42): error CS1014: A get or set accessor expected - DiagnosticResult.CompilerError("CS1014").WithSpan(10, 42, 10, 42), - // /0/Test0.cs(12,12): error CS1002: ; expected - DiagnosticResult.CompilerError("CS1002").WithSpan(12, 12, 12, 12), - // /0/Test0.cs(16,6): error CS1513: } expected - DiagnosticResult.CompilerError("CS1513").WithSpan(16, 6, 16, 6), - ], - source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545883")] - public async Task DoNotRemoveCastToInterfaceForSealedType9() - { - // Note: The cast below can't be removed (even though C is sealed) - // because it would result in binding to a Dispose method that doesn't - // implement IDisposable.Dispose(). + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545888")] + public async Task DoNotRemoveCastToInterfaceForSealedType8() + { + // Note: The cast below can't be removed (even though C is sealed) + // because the specified named arguments refer to parameters that + // appear at different positions in the member signatures. - var source = - """ - using System; - using System.IO; + var source = + """ + using System; - sealed class C : MemoryStream - { - static void Main() + interface I { - C s = new C(); - ((IDisposable)s).Dispose(); + int this[int x = 0, int y = 0] { get; } } - new public void Dispose() + sealed class C : I { - Console.WriteLine("new Dispose()"); + public int this(int y = 0, int x = 0) + { + get + { + return x * 2; + } + } + + static void Main() + { + Console.WriteLine(((I)new C())[x: 1]); + } } - } - """; + """; + + await VerifyCS.VerifyCodeFixAsync( + source, + [ + // /0/Test0.cs(8,18): error CS0535: 'C' does not implement interface member 'I.this[int, int]' + DiagnosticResult.CompilerError("CS0535").WithSpan(8, 18, 8, 19).WithArguments("C", "I.this[int, int]"), + // /0/Test0.cs(10,16): error CS0548: 'C.this[(int y, ?), int]': property or indexer must have at least one accessor + DiagnosticResult.CompilerError("CS0548").WithSpan(10, 16, 10, 20).WithArguments("C.this[(int y, ?), int]"), + // /0/Test0.cs(10,20): error CS1003: Syntax error, '[' expected + DiagnosticResult.CompilerError("CS1003").WithSpan(10, 20, 10, 21).WithArguments("["), + // /0/Test0.cs(10,27): error CS1750: A value of type 'int' cannot be used as a default parameter because there are no standard conversions to type '(int y, ?)' + DiagnosticResult.CompilerError("CS1750").WithSpan(10, 27, 10, 27).WithArguments("int", "(int y, ?)"), + // /0/Test0.cs(10,27): error CS1001: Identifier expected + DiagnosticResult.CompilerError("CS1001").WithSpan(10, 27, 10, 28), + // /0/Test0.cs(10,27): error CS1026: ) expected + DiagnosticResult.CompilerError("CS1026").WithSpan(10, 27, 10, 28), + // /0/Test0.cs(10,27): error CS8124: Tuple must contain at least two elements. + DiagnosticResult.CompilerError("CS8124").WithSpan(10, 27, 10, 28), + // /0/Test0.cs(10,41): error CS1003: Syntax error, ']' expected + DiagnosticResult.CompilerError("CS1003").WithSpan(10, 41, 10, 42).WithArguments("]"), + // /0/Test0.cs(10,41): error CS1014: A get or set accessor expected + DiagnosticResult.CompilerError("CS1014").WithSpan(10, 41, 10, 42), + // /0/Test0.cs(10,41): error CS1514: { expected + DiagnosticResult.CompilerError("CS1514").WithSpan(10, 41, 10, 42), + // /0/Test0.cs(10,42): error CS1014: A get or set accessor expected + DiagnosticResult.CompilerError("CS1014").WithSpan(10, 42, 10, 42), + // /0/Test0.cs(12,12): error CS1002: ; expected + DiagnosticResult.CompilerError("CS1002").WithSpan(12, 12, 12, 12), + // /0/Test0.cs(16,6): error CS1513: } expected + DiagnosticResult.CompilerError("CS1513").WithSpan(16, 6, 16, 6), + ], + source); + } + + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545883")] + public async Task DoNotRemoveCastToInterfaceForSealedType9() + { + // Note: The cast below can't be removed (even though C is sealed) + // because it would result in binding to a Dispose method that doesn't + // implement IDisposable.Dispose(). - await VerifyCS.VerifyCodeFixAsync(source, source); - } + var source = + """ + using System; + using System.IO; - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545887")] - public async Task DoNotRemoveCastToInterfaceForStruct1() - { - // Note: The cast below can't be removed because the cast boxes 's' and - // unboxing would change program behavior. + sealed class C : MemoryStream + { + static void Main() + { + C s = new C(); + ((IDisposable)s).Dispose(); + } - var source = - """ - using System; + new public void Dispose() + { + Console.WriteLine("new Dispose()"); + } + } + """; - interface IIncrementable - { - int Value { get; } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - void Increment(); - } + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545887")] + public async Task DoNotRemoveCastToInterfaceForStruct1() + { + // Note: The cast below can't be removed because the cast boxes 's' and + // unboxing would change program behavior. - struct S : IIncrementable - { - public int Value { get; private set; } + var source = + """ + using System; - public void Increment() + interface IIncrementable { - Value++; + int Value { get; } + + void Increment(); } - static void Main() + struct S : IIncrementable { - var s = new S(); - ((IIncrementable)s).Increment(); - Console.WriteLine(s.Value); + public int Value { get; private set; } + + public void Increment() + { + Value++; + } + + static void Main() + { + var s = new S(); + ((IIncrementable)s).Increment(); + Console.WriteLine(s.Value); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545834")] - [WorkItem("https://github.com/dotnet/roslyn/issues/34326")] - public async Task RemoveCastToInterfaceForStruct2() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - using System.Collections.Generic; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545834")] + [WorkItem("https://github.com/dotnet/roslyn/issues/34326")] + public async Task RemoveCastToInterfaceForStruct2() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + using System.Collections.Generic; - class Program - { - static void Main() + class Program { - ([|(IDisposable)|]GetEnumerator()).Dispose(); - } + static void Main() + { + ([|(IDisposable)|]GetEnumerator()).Dispose(); + } - static List.Enumerator GetEnumerator() - { - var x = new List { 1, 2, 3 }; - return x.GetEnumerator(); + static List.Enumerator GetEnumerator() + { + var x = new List { 1, 2, 3 }; + return x.GetEnumerator(); + } } - } - """, - """ - using System; - using System.Collections.Generic; + """, + """ + using System; + using System.Collections.Generic; - class Program - { - static void Main() + class Program { - GetEnumerator().Dispose(); - } + static void Main() + { + GetEnumerator().Dispose(); + } - static List.Enumerator GetEnumerator() - { - var x = new List { 1, 2, 3 }; - return x.GetEnumerator(); + static List.Enumerator GetEnumerator() + { + var x = new List { 1, 2, 3 }; + return x.GetEnumerator(); + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544655")] - public async Task RemoveCastToICloneableForDelegate() - { - // Note: The cast below can be removed because delegates are implicitly - // sealed. + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544655")] + public async Task RemoveCastToICloneableForDelegate() + { + // Note: The cast below can be removed because delegates are implicitly + // sealed. - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - class C - { - static void Main() + class C { - Action a = () => { }; - var c = ([|(ICloneable)|]a).Clone(); + static void Main() + { + Action a = () => { }; + var c = ([|(ICloneable)|]a).Clone(); + } } - } - """, + """, - """ - using System; + """ + using System; - class C - { - static void Main() + class C { - Action a = () => { }; - var c = a.Clone(); + static void Main() + { + Action a = () => { }; + var c = a.Clone(); + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545926")] - public async Task RemoveCastToICloneableForArray() - { - // Note: The cast below can be removed because arrays are implicitly - // sealed. + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545926")] + public async Task RemoveCastToICloneableForArray() + { + // Note: The cast below can be removed because arrays are implicitly + // sealed. - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - class C - { - static void Main() + class C { - var a = new[] { 1, 2, 3 }; - var c = ([|(ICloneable)|]a).Clone(); + static void Main() + { + var a = new[] { 1, 2, 3 }; + var c = ([|(ICloneable)|]a).Clone(); + } } - } - """, + """, - """ - using System; + """ + using System; - class C - { - static void Main() + class C { - var a = new[] { 1, 2, 3 }; - var c = a.Clone(); + static void Main() + { + var a = new[] { 1, 2, 3 }; + var c = a.Clone(); + } } - } - """); - } + """); + } - [Fact] - public async Task RemoveCastToInterfaceForString() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - using System.Collections.Generic; + [Fact] + public async Task RemoveCastToInterfaceForString() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + using System.Collections.Generic; - class C - { - static void Main(string s) + class C { - IEnumerable i = [|(IEnumerable)|]s; + static void Main(string s) + { + IEnumerable i = [|(IEnumerable)|]s; + } } - } - """, + """, - """ - using System; - using System.Collections.Generic; + """ + using System; + using System.Collections.Generic; - class C - { - static void Main(string s) + class C { - IEnumerable i = s; + static void Main(string s) + { + IEnumerable i = s; + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529897")] - public async Task RemoveCastToIConvertibleForEnum() - { - // Note: The cast below can be removed because enums are implicitly - // sealed. + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529897")] + public async Task RemoveCastToIConvertibleForEnum() + { + // Note: The cast below can be removed because enums are implicitly + // sealed. - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - class Program - { - static void Main() + class Program { - Enum e = DayOfWeek.Monday; - var y = ([|(IConvertible)|]e).GetTypeCode(); + static void Main() + { + Enum e = DayOfWeek.Monday; + var y = ([|(IConvertible)|]e).GetTypeCode(); + } } - } - """, + """, - """ - using System; + """ + using System; - class Program - { - static void Main() + class Program { - Enum e = DayOfWeek.Monday; - var y = e.GetTypeCode(); + static void Main() + { + Enum e = DayOfWeek.Monday; + var y = e.GetTypeCode(); + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529897")] - public async Task KeepCastToIConvertibleOnNonCopiedStruct() - { - var source = """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529897")] + public async Task KeepCastToIConvertibleOnNonCopiedStruct() + { + var source = """ + using System; - class Program - { - static void Main(DateTime dt) + class Program { - var y = ((IConvertible)dt).GetTypeCode(); + static void Main(DateTime dt) + { + var y = ((IConvertible)dt).GetTypeCode(); + } } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529897")] - public async Task RemoveCastToIConvertibleOnCopiedStruct1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529897")] + public async Task RemoveCastToIConvertibleOnCopiedStruct1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - class Program - { - static void Main() + class Program { - var y = ([|(IConvertible)|](DateTime.Now + TimeSpan.Zero)).GetTypeCode(); + static void Main() + { + var y = ([|(IConvertible)|](DateTime.Now + TimeSpan.Zero)).GetTypeCode(); + } } - } - """, """ - using System; + """, """ + using System; - class Program - { - static void Main() + class Program { - var y = (DateTime.Now + TimeSpan.Zero).GetTypeCode(); + static void Main() + { + var y = (DateTime.Now + TimeSpan.Zero).GetTypeCode(); + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529897")] - public async Task KeepCastToIConvertibleOnByRefIndexer() - { - var source = """ - using System; - - class Program - { - ref DateTime this[int i] => ref this[i]; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529897")] + public async Task KeepCastToIConvertibleOnByRefIndexer() + { + var source = """ + using System; - void Main() + class Program { - var y = ((IConvertible)this[0]).GetTypeCode(); - } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + ref DateTime this[int i] => ref this[i]; - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529897")] - public async Task RemoveCastToIConvertibleOnIndexer() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + void Main() + { + var y = ((IConvertible)this[0]).GetTypeCode(); + } + } + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - class Program - { - DateTime this[int i] => default; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529897")] + public async Task RemoveCastToIConvertibleOnIndexer() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - void Main() + class Program { - var y = ([|(IConvertible)|]this[0]).GetTypeCode(); - } - } - """, - """ - using System; + DateTime this[int i] => default; - class Program - { - DateTime this[int i] => default; + void Main() + { + var y = ([|(IConvertible)|]this[0]).GetTypeCode(); + } + } + """, + """ + using System; - void Main() + class Program { - var y = this[0].GetTypeCode(); - } - } - """); - } + DateTime this[int i] => default; - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529897")] - public async Task KeepCastToIConvertibleOnByRefProperty() - { - var source = """ - using System; + void Main() + { + var y = this[0].GetTypeCode(); + } + } + """); + } - class Program - { - ref DateTime X => ref X; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529897")] + public async Task KeepCastToIConvertibleOnByRefProperty() + { + var source = """ + using System; - void Main() + class Program { - var y = ((IConvertible)X).GetTypeCode(); - } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + ref DateTime X => ref X; - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529897")] - public async Task RemoveCastToIConvertibleOnProperty() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + void Main() + { + var y = ((IConvertible)X).GetTypeCode(); + } + } + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - class Program - { - DateTime X => default; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529897")] + public async Task RemoveCastToIConvertibleOnProperty() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - void Main() + class Program { - var y = ([|(IConvertible)|]X).GetTypeCode(); - } - } - """, - """ - using System; + DateTime X => default; - class Program - { - DateTime X => default; + void Main() + { + var y = ([|(IConvertible)|]X).GetTypeCode(); + } + } + """, + """ + using System; - void Main() + class Program { - var y = X.GetTypeCode(); - } - } - """); - } + DateTime X => default; - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529897")] - public async Task KeepCastToIConvertibleOnByRefMethod() - { - var source = """ - using System; + void Main() + { + var y = X.GetTypeCode(); + } + } + """); + } - class Program - { - ref DateTime X() => ref X(); + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529897")] + public async Task KeepCastToIConvertibleOnByRefMethod() + { + var source = """ + using System; - void Main() + class Program { - var y = ((IConvertible)X()).GetTypeCode(); - } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + ref DateTime X() => ref X(); - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529897")] - public async Task RemoveCastToIConvertibleOnMethod() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + void Main() + { + var y = ((IConvertible)X()).GetTypeCode(); + } + } + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - class Program - { - DateTime X() => default; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529897")] + public async Task RemoveCastToIConvertibleOnMethod() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - void Main() + class Program { - var y = ([|(IConvertible)|]X()).GetTypeCode(); - } - } - """, - """ - using System; + DateTime X() => default; - class Program - { - DateTime X() => default; + void Main() + { + var y = ([|(IConvertible)|]X()).GetTypeCode(); + } + } + """, + """ + using System; - void Main() + class Program { - var y = X().GetTypeCode(); + DateTime X() => default; + + void Main() + { + var y = X().GetTypeCode(); + } } - } - """); - } + """); + } - #endregion + #endregion - #region ParamArray Parameter Casts + #region ParamArray Parameter Casts - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545141")] - public async Task DoNotRemoveCastToObjectInParamArrayArg1() - { - var source = - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545141")] + public async Task DoNotRemoveCastToObjectInParamArrayArg1() + { + var source = + """ + using System; - class C - { - static void Main() + class C { - Goo((object)null); - } + static void Main() + { + Goo((object)null); + } - static void Goo(params object[] x) - { - Console.WriteLine(x.Length); + static void Goo(params object[] x) + { + Console.WriteLine(x.Length); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529911")] - public async Task DoNotRemoveCastToIntArrayInParamArrayArg2() - { - var source = - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529911")] + public async Task DoNotRemoveCastToIntArrayInParamArrayArg2() + { + var source = + """ + using System; - class C - { - static void Main() + class C { - Goo((int[])null); - } + static void Main() + { + Goo((int[])null); + } - static void Goo(params object[] x) - { - Console.WriteLine(x.Length); + static void Goo(params object[] x) + { + Console.WriteLine(x.Length); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529911")] - public async Task DoNotRemoveCastToObjectArrayInParamArrayArg3() - { - var source = - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529911")] + public async Task DoNotRemoveCastToObjectArrayInParamArrayArg3() + { + var source = + """ + using System; - class C - { - static void Main() + class C { - Goo((object[])null); - } + static void Main() + { + Goo((object[])null); + } - static void Goo(params object[][] x) - { - Console.WriteLine(x.Length); + static void Goo(params object[][] x) + { + Console.WriteLine(x.Length); + } } - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } + """; - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529911")] - public async Task RemoveCastToObjectArrayInParamArrayArg1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class C - { - static void Goo(params object[] x) { } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - static void Main() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529911")] + public async Task RemoveCastToObjectArrayInParamArrayArg1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class C { - Goo([|(object[])|]null); - } - } - """, + static void Goo(params object[] x) { } - """ - class C - { - static void Goo(params object[] x) { } + static void Main() + { + Goo([|(object[])|]null); + } + } + """, - static void Main() + """ + class C { - Goo(null); - } - } - """); - } + static void Goo(params object[] x) { } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529911")] - public async Task RemoveCastToStringArrayInParamArrayArg2() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class C - { - static void Goo(params object[] x) { } + static void Main() + { + Goo(null); + } + } + """); + } - static void Main() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529911")] + public async Task RemoveCastToStringArrayInParamArrayArg2() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class C { - Goo([|(string[])|]null); - } - } - """, + static void Goo(params object[] x) { } - """ - class C - { - static void Goo(params object[] x) { } + static void Main() + { + Goo([|(string[])|]null); + } + } + """, - static void Main() + """ + class C { - Goo(null); - } - } - """); - } + static void Goo(params object[] x) { } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529911")] - public async Task RemoveCastToIntArrayInParamArrayArg3() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class C - { - static void Goo(params int[] x) { } + static void Main() + { + Goo(null); + } + } + """); + } - static void Main() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529911")] + public async Task RemoveCastToIntArrayInParamArrayArg3() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class C { - Goo([|(int[])|]null); - } - } - """, + static void Goo(params int[] x) { } - """ - class C - { - static void Goo(params int[] x) { } + static void Main() + { + Goo([|(int[])|]null); + } + } + """, - static void Main() + """ + class C { - Goo(null); + static void Goo(params int[] x) { } + + static void Main() + { + Goo(null); + } } - } - """); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529911")] - public async Task RemoveCastToObjectArrayInParamArrayArg4() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class C - { - static void Goo(params object[] x) { } - - static void Main() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529911")] + public async Task RemoveCastToObjectArrayInParamArrayArg4() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class C { - Goo([|(object[])|]null, null); - } - } - """, - - """ - class C - { - static void Goo(params object[] x) { } + static void Goo(params object[] x) { } - static void Main() - { - Goo(null, null); + static void Main() + { + Goo([|(object[])|]null, null); + } } - } - """); - } - - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529911")] - public async Task RemoveCastToObjectInParamArrayArg5() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class C - { - static void Goo(params object[] x) { } + """, - static void Main() + """ + class C { - Goo([|(object)|]null, null); - } - } - """, + static void Goo(params object[] x) { } - """ - class C - { - static void Goo(params object[] x) { } + static void Main() + { + Goo(null, null); + } + } + """); + } - static void Main() + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529911")] + public async Task RemoveCastToObjectInParamArrayArg5() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class C { - Goo(null, null); + static void Goo(params object[] x) { } + + static void Main() + { + Goo([|(object)|]null, null); + } } - } - """); - } + """, - [Fact] - public async Task RemoveCastToObjectArrayInParamArrayWithNamedArgument() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class C - { - static void Main() + """ + class C { - Goo(x: [|(object[])|]null); + static void Goo(params object[] x) { } + + static void Main() + { + Goo(null, null); + } } + """); + } - static void Goo(params object[] x) { } - } - """, - """ - class C - { - static void Main() + [Fact] + public async Task RemoveCastToObjectArrayInParamArrayWithNamedArgument() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class C { - Goo(x: null); + static void Main() + { + Goo(x: [|(object[])|]null); + } + + static void Goo(params object[] x) { } } + """, + """ + class C + { + static void Main() + { + Goo(x: null); + } - static void Goo(params object[] x) { } - } - """); - } + static void Goo(params object[] x) { } + } + """); + } - #endregion + #endregion - #region ForEach Statements + #region ForEach Statements - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545961")] - public async Task DoNotRemoveNecessaryCastInForEach1() - { - // The cast below can't be removed because it would result an error - // in the foreach statement. + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545961")] + public async Task DoNotRemoveNecessaryCastInForEach1() + { + // The cast below can't be removed because it would result an error + // in the foreach statement. - var source = - """ - using System.Collections; + var source = + """ + using System.Collections; - class Program - { - static void Main() + class Program { - object s = "; - foreach (object x in (IEnumerable)s) + static void Main() { + object s = "; + foreach (object x in (IEnumerable)s) + { + } } } - } - """; - - await VerifyCS.VerifyCodeFixAsync( - source, - [ - // /0/Test0.cs(7,20): error CS1010: Newline in constant - DiagnosticResult.CompilerError("CS1010").WithSpan(7, 20, 7, 20), - // /0/Test0.cs(7,22): error CS1002: ; expected - DiagnosticResult.CompilerError("CS1002").WithSpan(7, 22, 7, 22), - ], - source); - } - - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545961")] - public async Task DoNotRemoveNecessaryCastInForEach2() - { - // The cast below can't be removed because it would result an error - // in the foreach statement. + """; + + await VerifyCS.VerifyCodeFixAsync( + source, + [ + // /0/Test0.cs(7,20): error CS1010: Newline in constant + DiagnosticResult.CompilerError("CS1010").WithSpan(7, 20, 7, 20), + // /0/Test0.cs(7,22): error CS1002: ; expected + DiagnosticResult.CompilerError("CS1002").WithSpan(7, 22, 7, 22), + ], + source); + } + + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545961")] + public async Task DoNotRemoveNecessaryCastInForEach2() + { + // The cast below can't be removed because it would result an error + // in the foreach statement. - var source = - """ - using System.Collections.Generic; + var source = + """ + using System.Collections.Generic; - class Program - { - static void Main() + class Program { - object s = "; - foreach (object x in (IEnumerable)s) + static void Main() { + object s = "; + foreach (object x in (IEnumerable)s) + { + } } } - } - """; - - await VerifyCS.VerifyCodeFixAsync( - source, - [ - // /0/Test0.cs(7,20): error CS1010: Newline in constant - DiagnosticResult.CompilerError("CS1010").WithSpan(7, 20, 7, 20), - // /0/Test0.cs(7,22): error CS1002: ; expected - DiagnosticResult.CompilerError("CS1002").WithSpan(7, 22, 7, 22), - ], - source); - } - - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545961")] - public async Task DoNotRemoveNecessaryCastInForEach3() - { - // The cast below can't be removed because it would result an error - // in the foreach statement since C doesn't contain a GetEnumerator() - // method. + """; + + await VerifyCS.VerifyCodeFixAsync( + source, + [ + // /0/Test0.cs(7,20): error CS1010: Newline in constant + DiagnosticResult.CompilerError("CS1010").WithSpan(7, 20, 7, 20), + // /0/Test0.cs(7,22): error CS1002: ; expected + DiagnosticResult.CompilerError("CS1002").WithSpan(7, 22, 7, 22), + ], + source); + } + + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545961")] + public async Task DoNotRemoveNecessaryCastInForEach3() + { + // The cast below can't be removed because it would result an error + // in the foreach statement since C doesn't contain a GetEnumerator() + // method. - var source = - """ - using System.Collections; + var source = + """ + using System.Collections; - class D - { - public IEnumerator GetEnumerator() + class D { - yield return 1; + public IEnumerator GetEnumerator() + { + yield return 1; + } } - } - class C - { - public static implicit operator D(C c) + class C { - return new D(); - } + public static implicit operator D(C c) + { + return new D(); + } - static void Main() - { - object s = "; - foreach (object x in (D)new C()) + static void Main() { + object s = "; + foreach (object x in (D)new C()) + { + } } } - } - """; - - await VerifyCS.VerifyCodeFixAsync( - source, - [ - // /0/Test0.cs(20,20): error CS1010: Newline in constant - DiagnosticResult.CompilerError("CS1010").WithSpan(20, 20, 20, 20), - // /0/Test0.cs(20,22): error CS1002: ; expected - DiagnosticResult.CompilerError("CS1002").WithSpan(20, 22, 20, 22), - ], - source); - } - - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545961")] - public async Task DoNotRemoveNecessaryCastInForEach4() - { - // The cast below can't be removed because it would result in - // C.GetEnumerator() being called rather than D.GetEnumerator(). + """; + + await VerifyCS.VerifyCodeFixAsync( + source, + [ + // /0/Test0.cs(20,20): error CS1010: Newline in constant + DiagnosticResult.CompilerError("CS1010").WithSpan(20, 20, 20, 20), + // /0/Test0.cs(20,22): error CS1002: ; expected + DiagnosticResult.CompilerError("CS1002").WithSpan(20, 22, 20, 22), + ], + source); + } + + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545961")] + public async Task DoNotRemoveNecessaryCastInForEach4() + { + // The cast below can't be removed because it would result in + // C.GetEnumerator() being called rather than D.GetEnumerator(). - var source = - """ - using System; - using System.Collections; + var source = + """ + using System; + using System.Collections; - class D - { - public IEnumerator GetEnumerator() + class D { - yield return 1; + public IEnumerator GetEnumerator() + { + yield return 1; + } } - } - class C - { - public IEnumerator GetEnumerator() + class C { - yield return 2; - } + public IEnumerator GetEnumerator() + { + yield return 2; + } - public static implicit operator D(C c) - { - return new D(); - } + public static implicit operator D(C c) + { + return new D(); + } - static void Main() - { - object s = "; - foreach (object x in (D)new C()) + static void Main() { - Console.WriteLine(x); + object s = "; + foreach (object x in (D)new C()) + { + Console.WriteLine(x); + } } } - } - """; - - await VerifyCS.VerifyCodeFixAsync( - source, - [ - // /0/Test0.cs(26,20): error CS1010: Newline in constant - DiagnosticResult.CompilerError("CS1010").WithSpan(26, 20, 26, 20), - // /0/Test0.cs(26,22): error CS1002: ; expected - DiagnosticResult.CompilerError("CS1002").WithSpan(26, 22, 26, 22), - ], - source); - } - - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545961")] - public async Task DoNotRemoveNecessaryCastInForEach5() - { - // The cast below can't be removed because it would change the - // type of 'x'. + """; + + await VerifyCS.VerifyCodeFixAsync( + source, + [ + // /0/Test0.cs(26,20): error CS1010: Newline in constant + DiagnosticResult.CompilerError("CS1010").WithSpan(26, 20, 26, 20), + // /0/Test0.cs(26,22): error CS1002: ; expected + DiagnosticResult.CompilerError("CS1002").WithSpan(26, 22, 26, 22), + ], + source); + } + + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545961")] + public async Task DoNotRemoveNecessaryCastInForEach5() + { + // The cast below can't be removed because it would change the + // type of 'x'. - var source = - """ - using System; + var source = + """ + using System; - class Program - { - static void Main() + class Program { - string[] s = { - "A" - }; - foreach (var x in (Array)s) + static void Main() { - var y = x; - y = 1; + string[] s = { + "A" + }; + foreach (var x in (Array)s) + { + var y = x; + y = 1; + } } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - #endregion + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545925")] - public async Task DoNotRemoveCastIfOverriddenMethodHasIncompatibleParameterList() - { - // Note: The cast below can't be removed because the parameter list - // of Goo and its override have different default values. + #endregion - var source = - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545925")] + public async Task DoNotRemoveCastIfOverriddenMethodHasIncompatibleParameterList() + { + // Note: The cast below can't be removed because the parameter list + // of Goo and its override have different default values. - abstract class Y - { - public abstract void Goo(int x = 1); - } + var source = + """ + using System; - class X : Y - { - static void Main() + abstract class Y { - ((Y)new X()).Goo(); + public abstract void Goo(int x = 1); } - public override void Goo(int x = 2) + class X : Y { - Console.WriteLine(x); - } - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545925")] - public async Task RemoveCastIfOverriddenMethodHaveCompatibleParameterList() - { - // Note: The cast below can be removed because the parameter list - // of Goo and its override have the same default values. - - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - - abstract class Y - { - public abstract void Goo(int x = 1); - } + static void Main() + { + ((Y)new X()).Goo(); + } - class X : Y - { - static void Main() - { - ([|(Y)|]new X()).Goo(); + public override void Goo(int x = 2) + { + Console.WriteLine(x); + } } + """; - public override void Goo(int x = 1) - { - Console.WriteLine(x); - } - } - """, + await VerifyCS.VerifyCodeFixAsync(source, source); + } - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545925")] + public async Task RemoveCastIfOverriddenMethodHaveCompatibleParameterList() + { + // Note: The cast below can be removed because the parameter list + // of Goo and its override have the same default values. - abstract class Y - { - public abstract void Goo(int x = 1); - } + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - class X : Y - { - static void Main() + abstract class Y { - new X().Goo(); + public abstract void Goo(int x = 1); } - public override void Goo(int x = 1) + class X : Y { - Console.WriteLine(x); - } - } - """); - } - - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529916")] - public async Task RemoveCastInReceiverForMethodGroup() - { - // Note: The cast below can be removed because the it results in - // the same method group. - - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + static void Main() + { + ([|(Y)|]new X()).Goo(); + } - static class Program - { - static void Main() - { - Action a = ([|(string)|]"").Goo; + public override void Goo(int x = 1) + { + Console.WriteLine(x); + } } + """, - static void Goo(this string x) { } - } - """, - - """ - using System; + """ + using System; - static class Program - { - static void Main() + abstract class Y { - Action a = "".Goo; + public abstract void Goo(int x = 1); } - static void Goo(this string x) { } - } - """); - } - - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/609497")] - public async Task Bugfix_609497() - { - var source = - """ - using System; - using System.Threading.Tasks; - - class Program - { - static void Main() + class X : Y { - Goo().Wait(); - } + static void Main() + { + new X().Goo(); + } - static async Task Goo() - { - Task task = Task.FromResult(0); - Console.WriteLine(await (dynamic)task); + public override void Goo(int x = 1) + { + Console.WriteLine(x); + } } - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } + """); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545995")] - public async Task DoNotRemoveCastToDifferentTypeWithSameName() - { - // Note: The cast below cannot be removed because the it results in - // a different overload being picked. + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529916")] + public async Task RemoveCastInReceiverForMethodGroup() + { + // Note: The cast below can be removed because the it results in + // the same method group. - var source = - """ - using System; - using MyInt = System.Int32; + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - namespace System - { - public struct Int32 + static class Program { - public static implicit operator Int32(int x) + static void Main() { - return default(Int32); + Action a = ([|(string)|]"").Goo; } - } - } - class A - { - static void Goo(int x) - { - Console.WriteLine("int"); + static void Goo(this string x) { } } + """, - static void Goo(MyInt x) - { - Console.WriteLine("MyInt"); - } + """ + using System; - static void Main() + static class Program { - Goo((MyInt)0); - } - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545921")] - public async Task DoNotRemoveCastWhichWouldChangeAttributeOverloadResolution1() - { - // Note: The cast below cannot be removed because it would result in - // a different attribute constructor being picked - - var source = - """ - using System; - - [Flags] - enum EEEnum - { - Flag1 = 0x2, - Flag2 = 0x1, - } + static void Main() + { + Action a = "".Goo; + } - class MyAttributeAttribute : Attribute - { - public MyAttributeAttribute(EEEnum e) - { + static void Goo(this string x) { } } + """); + } - public MyAttributeAttribute(short e) - { - } + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/609497")] + public async Task Bugfix_609497() + { + var source = + """ + using System; + using System.Threading.Tasks; - public void Goo(EEEnum e) + class Program { - } + static void Main() + { + Goo().Wait(); + } - public void Goo(short e) - { + static async Task Goo() + { + Task task = Task.FromResult(0); + Console.WriteLine(await (dynamic)task); + } } + """; - [MyAttribute((EEEnum)0x0)] - public void Bar() - { - Goo((EEEnum)0x0); - } - } - """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - await VerifyCS.VerifyCodeFixAsync(source, source); - } + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545995")] + public async Task DoNotRemoveCastToDifferentTypeWithSameName() + { + // Note: The cast below cannot be removed because the it results in + // a different overload being picked. - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/624252")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/608180")] - public async Task DoNotRemoveCastIfArgumentIsRestricted_TypedReference() - { - var source = - """ - using System; + var source = + """ + using System; + using MyInt = System.Int32; - class Program - { - static void Main(string[] args) + namespace System { + public struct Int32 + { + public static implicit operator Int32(int x) + { + return default(Int32); + } + } } - static void v(dynamic x) + class A { - var y = default(TypedReference); - dd((object)x, y); - } + static void Goo(int x) + { + Console.WriteLine("int"); + } - static void dd(object obj, TypedReference d) - { - } - } - """; + static void Goo(MyInt x) + { + Console.WriteLine("MyInt"); + } - await VerifyCS.VerifyCodeFixAsync(source, source); - } + static void Main() + { + Goo((MyInt)0); + } + } + """; - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/627107")] - public async Task DoNotRemoveCastOnArgumentsWithOtherDynamicArguments() - { - var source = - """ - using System; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - class Program - { - static void Main() - { - C.InvokeGoo(0); - } - } + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545921")] + public async Task DoNotRemoveCastWhichWouldChangeAttributeOverloadResolution1() + { + // Note: The cast below cannot be removed because it would result in + // a different attribute constructor being picked - class C - { - public static void InvokeGoo(dynamic x) - { - Console.WriteLine(Goo(x, (object)"", "")); - } + var source = + """ + using System; - static void Goo(int x, string y, T z) + [Flags] + enum EEEnum { + Flag1 = 0x2, + Flag2 = 0x1, } - static bool Goo(int x, object y, object z) + class MyAttributeAttribute : Attribute { - return true; - } - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } + public MyAttributeAttribute(EEEnum e) + { + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/627107")] - public async Task DoNotRemoveCastOnArgumentsWithOtherDynamicArguments_Bracketed() - { - var source = - """ - class C - { - int this[int x, T s, string d = "abc"] - { - get + public MyAttributeAttribute(short e) { - return 0; } - set + public void Goo(EEEnum e) { } - } - int this[int x, object s, object d] - { - get + public void Goo(short e) { - return 0; } - set + [MyAttribute((EEEnum)0x0)] + public void Bar() { + Goo((EEEnum)0x0); } } + """; - void Goo(dynamic xx) + await VerifyCS.VerifyCodeFixAsync(source, source); + } + + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/624252")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/608180")] + public async Task DoNotRemoveCastIfArgumentIsRestricted_TypedReference() + { + var source = + """ + using System; + + class Program { - var y = this[x: xx, s: "", d: (object)""]; + static void Main(string[] args) + { + } + + static void v(dynamic x) + { + var y = default(TypedReference); + dd((object)x, y); + } + + static void dd(object obj, TypedReference d) + { + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/627107")] - public async Task DoNotRemoveCastOnArgumentsWithDynamicReceiverOpt() - { - var source = - """ - class C - { - static bool Goo(dynamic d) + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/627107")] + public async Task DoNotRemoveCastOnArgumentsWithOtherDynamicArguments() + { + var source = + """ + using System; + + class Program { - d((object)""); - return true; + static void Main() + { + C.InvokeGoo(0); + } } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/627107")] - public async Task DoNotRemoveCastOnArgumentsWithDynamicReceiverOpt_1() - { - var source = - """ - class C - { - static bool Goo(dynamic d) + class C { - d.goo((object)""); - return true; + public static void InvokeGoo(dynamic x) + { + Console.WriteLine(Goo(x, (object)"", "")); + } + + static void Goo(int x, string y, T z) + { + } + + static bool Goo(int x, object y, object z) + { + return true; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/627107")] - public async Task DoNotRemoveCastOnArgumentsWithDynamicReceiverOpt_2() - { - var source = - """ - class C - { - static bool Goo(dynamic d) + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/627107")] + public async Task DoNotRemoveCastOnArgumentsWithOtherDynamicArguments_Bracketed() + { + var source = + """ + class C { - d.goo.bar.goo((object)""); - return true; + int this[int x, T s, string d = "abc"] + { + get + { + return 0; + } + + set + { + } + } + + int this[int x, object s, object d] + { + get + { + return 0; + } + + set + { + } + } + + void Goo(dynamic xx) + { + var y = this[x: xx, s: "", d: (object)""]; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/627107")] - public async Task DoNotRemoveCastOnArgumentsWithDynamicReceiverOpt_3() - { - var source = - """ - class C - { - static bool Goo(dynamic d) + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/627107")] + public async Task DoNotRemoveCastOnArgumentsWithDynamicReceiverOpt() + { + var source = + """ + class C { - d.goo().bar().goo((object)""); - return true; + static bool Goo(dynamic d) + { + d((object)""); + return true; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/627107")] - public async Task DoNotRemoveCastOnArgumentsWithOtherDynamicArguments_1() - { - var source = - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/627107")] + public async Task DoNotRemoveCastOnArgumentsWithDynamicReceiverOpt_1() + { + var source = + """ + class C + { + static bool Goo(dynamic d) + { + d.goo((object)""); + return true; + } + } + """; - class Program - { - static void Main() + await VerifyCS.VerifyCodeFixAsync(source, source); + } + + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/627107")] + public async Task DoNotRemoveCastOnArgumentsWithDynamicReceiverOpt_2() + { + var source = + """ + class C { - C.InvokeGoo(0); + static bool Goo(dynamic d) + { + d.goo.bar.goo((object)""); + return true; + } } - } + """; - class C - { - public static void InvokeGoo(dynamic x) + await VerifyCS.VerifyCodeFixAsync(source, source); + } + + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/627107")] + public async Task DoNotRemoveCastOnArgumentsWithDynamicReceiverOpt_3() + { + var source = + """ + class C { - Console.WriteLine(Goo((object)"", x, "")); + static bool Goo(dynamic d) + { + d.goo().bar().goo((object)""); + return true; + } } + """; + + await VerifyCS.VerifyCodeFixAsync(source, source); + } - static void Goo(string y, int x, T z) + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/627107")] + public async Task DoNotRemoveCastOnArgumentsWithOtherDynamicArguments_1() + { + var source = + """ + using System; + + class Program { + static void Main() + { + C.InvokeGoo(0); + } } - static bool Goo(object y, int x, object z) + class C { - return true; + public static void InvokeGoo(dynamic x) + { + Console.WriteLine(Goo((object)"", x, "")); + } + + static void Goo(string y, int x, T z) + { + } + + static bool Goo(object y, int x, object z) + { + return true; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545998")] - public async Task DoNotRemoveCastWhichWouldChangeAttributeOverloadResolution2() - { - // Note: The cast below cannot be removed because it would result in - // a different attribute constructor being picked + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545998")] + public async Task DoNotRemoveCastWhichWouldChangeAttributeOverloadResolution2() + { + // Note: The cast below cannot be removed because it would result in + // a different attribute constructor being picked - var source = - """ - using System; + var source = + """ + using System; - [A(new[] { (long)0 })] - class A : Attribute - { - public A(long[] x) + [A(new[] { (long)0 })] + class A : Attribute { + public A(long[] x) + { + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529894")] - public async Task DoNotUnnecessaryCastFromEnumToUint() - { - var source = - """ - using System; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529894")] + public async Task DoNotUnnecessaryCastFromEnumToUint() + { + var source = + """ + using System; - enum E - { - X = -1 - } + enum E + { + X = -1 + } - class C - { - static void Main() + class C { - E x = E.X; - Console.WriteLine((uint)x > 0); + static void Main() + { + E x = E.X; + Console.WriteLine((uint)x > 0); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529846")] - public async Task DoNotUnnecessaryCastFromTypeParameterToObject() - { - var source = - """ - class C - { - static void Goo(T x, object y) + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529846")] + public async Task DoNotUnnecessaryCastFromTypeParameterToObject() + { + var source = + """ + class C { - if ((object)x == y) + static void Goo(T x, object y) { + if ((object)x == y) + { + } } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/640136")] - public async Task RemoveUnnecessaryCastAndParseCorrect() - { - var source = - """ - using System; - using System.Threading.Tasks; + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/640136")] + public async Task RemoveUnnecessaryCastAndParseCorrect() + { + var source = + """ + using System; + using System.Threading.Tasks; - class C - { - void Goo(Task x) + class C { - (([|(Task)|]x).Result)(); + void Goo(Task x) + { + (([|(Task)|]x).Result)(); + } } - } - """; - var fixedSource = - """ - using System; - using System.Threading.Tasks; + """; + var fixedSource = + """ + using System; + using System.Threading.Tasks; - class C - { - void Goo(Task x) + class C { - (x.Result)(); + void Goo(Task x) + { + (x.Result)(); + } } - } - """; + """; - await new VerifyCS.Test - { - TestCode = source, - FixedState = + await new VerifyCS.Test { - Sources = { fixedSource }, - ExpectedDiagnostics = + TestCode = source, + FixedState = { - // /0/Test0.cs(9,10): error CS0118: 'x' is a variable but is used like a type - DiagnosticResult.CompilerError("CS0118").WithSpan(8, 10, 8, 11).WithArguments("x", "variable", "type"), - // /0/Test0.cs(9,20): error CS1525: Invalid expression term ')' - DiagnosticResult.CompilerError("CS1525").WithSpan(8, 20, 8, 21).WithArguments(")"), + Sources = { fixedSource }, + ExpectedDiagnostics = + { + // /0/Test0.cs(9,10): error CS0118: 'x' is a variable but is used like a type + DiagnosticResult.CompilerError("CS0118").WithSpan(8, 10, 8, 11).WithArguments("x", "variable", "type"), + // /0/Test0.cs(9,20): error CS1525: Invalid expression term ')' + DiagnosticResult.CompilerError("CS1525").WithSpan(8, 20, 8, 21).WithArguments(")"), + }, }, - }, - // The code fix in this case does not produce valid code or a valid syntax tree - CodeActionValidationMode = CodeActionValidationMode.None, - }.RunAsync(); - } + // The code fix in this case does not produce valid code or a valid syntax tree + CodeActionValidationMode = CodeActionValidationMode.None, + }.RunAsync(); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/626026")] - public async Task DoNotRemoveCastIfUserDefinedExplicitCast() - { - var source = - """ - class Program - { - static void Main(string[] args) + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/626026")] + public async Task DoNotRemoveCastIfUserDefinedExplicitCast() + { + var source = + """ + class Program { - B bar = new B(); - A a = (A)bar; + static void Main(string[] args) + { + B bar = new B(); + A a = (A)bar; + } } - } - public struct A - { - public static explicit operator A(B b) + public struct A { - return new A(); + public static explicit operator A(B b) + { + return new A(); + } } - } - - public struct B - { - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/768895")] - public async Task DoNotRemoveNecessaryCastInTernary() - { - var source = - """ - class Program - { - static void Main(string[] args) + public struct B { - object x = null; - int y = (bool)x ? 1 : 0; } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/770187")] - public async Task DoNotRemoveNecessaryCastInSwitchExpression() - { - var source = - """ - namespace ConsoleApplication23 - { + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/768895")] + public async Task DoNotRemoveNecessaryCastInTernary() + { + var source = + """ class Program { static void Main(string[] args) { - int goo = 0; - switch ((E)goo) - { - case E.A: - case E.B: - return; - } + object x = null; + int y = (bool)x ? 1 : 0; } } + """; - enum E + await VerifyCS.VerifyCodeFixAsync(source, source); + } + + [Fact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/770187")] + public async Task DoNotRemoveNecessaryCastInSwitchExpression() + { + var source = + """ + namespace ConsoleApplication23 { - A, - B, - C + class Program + { + static void Main(string[] args) + { + int goo = 0; + switch ((E)goo) + { + case E.A: + case E.B: + return; + } + } + } + + enum E + { + A, + B, + C + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2761")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/844482")] - public async Task DoNotRemoveCastFromBaseToDerivedWithExplicitReference() - { - var source = - """ - class Program - { - static void Main(string[] args) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/2761")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/844482")] + public async Task DoNotRemoveCastFromBaseToDerivedWithExplicitReference() + { + var source = + """ + class Program { - C x = null; - C y = null; - y = (D)x; + static void Main(string[] args) + { + C x = null; + C y = null; + y = (D)x; + } } - } - class C - { - } + class C + { + } - class D : C - { - } - """; + class D : C + { + } + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/3254")] - public async Task DoNotRemoveCastToTypeParameterWithExceptionConstraint() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/3254")] + public async Task DoNotRemoveCastToTypeParameterWithExceptionConstraint() + { + var source = + """ + using System; - class Program - { - private static void RequiresCondition(bool condition, string messageOnFalseCondition) where TException : Exception + class Program { - if (!condition) + private static void RequiresCondition(bool condition, string messageOnFalseCondition) where TException : Exception { - throw (TException)Activator.CreateInstance(typeof(TException), messageOnFalseCondition); + if (!condition) + { + throw (TException)Activator.CreateInstance(typeof(TException), messageOnFalseCondition); + } } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/3254")] - public async Task DoNotRemoveCastToTypeParameterWithExceptionSubTypeConstraint() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/3254")] + public async Task DoNotRemoveCastToTypeParameterWithExceptionSubTypeConstraint() + { + var source = + """ + using System; - class Program - { - private static void RequiresCondition(bool condition, string messageOnFalseCondition) where TException : ArgumentException + class Program { - if (!condition) + private static void RequiresCondition(bool condition, string messageOnFalseCondition) where TException : ArgumentException { - throw (TException)Activator.CreateInstance(typeof(TException), messageOnFalseCondition); + if (!condition) + { + throw (TException)Activator.CreateInstance(typeof(TException), messageOnFalseCondition); + } } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/8111")] - public async Task DoNotRemoveCastThatChangesShapeOfAnonymousTypeObject() - { - var source = - """ - class Program - { - static void Main(string[] args) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/8111")] + public async Task DoNotRemoveCastThatChangesShapeOfAnonymousTypeObject() + { + var source = + """ + class Program { - object thing = new { shouldBeAnInt = (int)Directions.South }; - } + static void Main(string[] args) + { + object thing = new { shouldBeAnInt = (int)Directions.South }; + } - public enum Directions - { - North, - East, - South, - West + public enum Directions + { + North, + East, + South, + West + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/8111")] - public async Task RemoveCastThatDoesntChangeShapeOfAnonymousTypeObject() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class Program - { - static void Main(string[] args) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/8111")] + public async Task RemoveCastThatDoesntChangeShapeOfAnonymousTypeObject() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class Program { - object thing = new { shouldBeAnInt = [|(Directions)|]Directions.South }; - } + static void Main(string[] args) + { + object thing = new { shouldBeAnInt = [|(Directions)|]Directions.South }; + } - public enum Directions - { - North, - East, - South, - West + public enum Directions + { + North, + East, + South, + West + } } - } - """, + """, - """ - class Program - { - static void Main(string[] args) + """ + class Program { - object thing = new { shouldBeAnInt = Directions.South }; - } + static void Main(string[] args) + { + object thing = new { shouldBeAnInt = Directions.South }; + } - public enum Directions - { - North, - East, - South, - West + public enum Directions + { + North, + East, + South, + West + } } - } - """); - } + """); + } - [Fact] - public async Task Tuple() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class C - { - void Main() + [Fact] + public async Task Tuple() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class C { - (int, string) tuple = [|((int, string))|](1, "hello"); + void Main() + { + (int, string) tuple = [|((int, string))|](1, "hello"); + } } - } - """, - """ - class C - { - void Main() + """, + """ + class C { - (int, string) tuple = (1, "hello"); + void Main() + { + (int, string) tuple = (1, "hello"); + } } - } - """); - } + """); + } - [Fact] - public async Task TupleWithDifferentNames() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class C - { - void Main() + [Fact] + public async Task TupleWithDifferentNames() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class C { - (int a, string) tuple = [|((int, string d))|](1, f: "hello"); + void Main() + { + (int a, string) tuple = [|((int, string d))|](1, f: "hello"); + } } - } - """, - """ - class C - { - void Main() + """, + """ + class C { - (int a, string) tuple = (1, f: "hello"); + void Main() + { + (int a, string) tuple = (1, f: "hello"); + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/24791")] - public async Task SimpleBoolCast() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class C - { - bool M() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/24791")] + public async Task SimpleBoolCast() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class C { - if (![|(bool)|]M()) throw null; - throw null; + bool M() + { + if (![|(bool)|]M()) throw null; + throw null; + } } - } - """, - """ - class C - { - bool M() + """, + """ + class C { - if (!M()) throw null; - throw null; + bool M() + { + if (!M()) throw null; + throw null; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/12572")] - public async Task DoNotRemoveCastThatUnboxes() - { - // The cast below can't be removed because it could throw a null ref exception. - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/12572")] + public async Task DoNotRemoveCastThatUnboxes() + { + // The cast below can't be removed because it could throw a null ref exception. + var source = + """ + using System; - class Program - { - static void Main() + class Program { - object i = null; - switch ((int)i) + static void Main() { - case 0: - Console.WriteLine(0); - break; - case 1: - Console.WriteLine(1); - break; - case 2: - Console.WriteLine(2); - break; + object i = null; + switch ((int)i) + { + case 0: + Console.WriteLine(0); + break; + case 1: + Console.WriteLine(1); + break; + case 2: + Console.WriteLine(2); + break; + } } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17029")] - public async Task DoNotRemoveCastOnEnumComparison1() - { - var source = - """ - enum TransferTypeKey - { - Transfer, - TransferToBeneficiary - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - class Program - { - static void Main(dynamic p) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17029")] + public async Task DoNotRemoveCastOnEnumComparison1() + { + var source = + """ + enum TransferTypeKey { - if (p.TYP != (int)TransferTypeKey.TransferToBeneficiary) - throw new InvalidOperationException(); + Transfer, + TransferToBeneficiary } - } - """; - - await VerifyCS.VerifyCodeFixAsync( - source, - // /0/Test0.cs(13,21): error CS0246: The type or namespace name 'InvalidOperationException' could not be found (are you missing a using directive or an assembly reference?) - DiagnosticResult.CompilerError("CS0246").WithSpan(12, 21, 12, 46).WithArguments("InvalidOperationException"), - source); - } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17029")] - public async Task DoNotRemoveCastOnEnumComparison2() - { - var source = - """ - enum TransferTypeKey - { - Transfer, - TransferToBeneficiary - } - - class Program - { - static void Main(dynamic p) + class Program { - if ((int)TransferTypeKey.TransferToBeneficiary != p.TYP) - throw new InvalidOperationException(); + static void Main(dynamic p) + { + if (p.TYP != (int)TransferTypeKey.TransferToBeneficiary) + throw new InvalidOperationException(); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync( - source, - // /0/Test0.cs(13,21): error CS0246: The type or namespace name 'InvalidOperationException' could not be found (are you missing a using directive or an assembly reference?) - DiagnosticResult.CompilerError("CS0246").WithSpan(12, 21, 12, 46).WithArguments("InvalidOperationException"), - source); - } + await VerifyCS.VerifyCodeFixAsync( + source, + // /0/Test0.cs(13,21): error CS0246: The type or namespace name 'InvalidOperationException' could not be found (are you missing a using directive or an assembly reference?) + DiagnosticResult.CompilerError("CS0246").WithSpan(12, 21, 12, 46).WithArguments("InvalidOperationException"), + source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/18978")] - public async Task DoNotRemoveCastOnCallToMethodWithParamsArgs() - { - var source = - """ - class Program - { - public static void Main(string[] args) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/17029")] + public async Task DoNotRemoveCastOnEnumComparison2() + { + var source = + """ + enum TransferTypeKey { - var takesArgs = new[] { "Hello", "World" }; - TakesParams((object)takesArgs); + Transfer, + TransferToBeneficiary } - private static void TakesParams(params object[] goo) + class Program { - Console.WriteLine(goo.Length); + static void Main(dynamic p) + { + if ((int)TransferTypeKey.TransferToBeneficiary != p.TYP) + throw new InvalidOperationException(); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync( - source, - // /0/Test0.cs(12,9): error CS0103: The name 'Console' does not exist in the current context - DiagnosticResult.CompilerError("CS0103").WithSpan(11, 9, 11, 16).WithArguments("Console"), - source); - } + await VerifyCS.VerifyCodeFixAsync( + source, + // /0/Test0.cs(13,21): error CS0246: The type or namespace name 'InvalidOperationException' could not be found (are you missing a using directive or an assembly reference?) + DiagnosticResult.CompilerError("CS0246").WithSpan(12, 21, 12, 46).WithArguments("InvalidOperationException"), + source); + } - [Fact] - public async Task DoRemoveCastOnCallToMethodWithInvalidParamsArgs() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class Program - { - public static void Main(string[] args) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/18978")] + public async Task DoNotRemoveCastOnCallToMethodWithParamsArgs() + { + var source = + """ + class Program { - TakesParams([|(string)|]null); + public static void Main(string[] args) + { + var takesArgs = new[] { "Hello", "World" }; + TakesParams((object)takesArgs); + } + + private static void TakesParams(params object[] goo) + { + Console.WriteLine(goo.Length); + } } + """; - private static void TakesParams({|CS0225:params|} string wrongDefined) + await VerifyCS.VerifyCodeFixAsync( + source, + // /0/Test0.cs(12,9): error CS0103: The name 'Console' does not exist in the current context + DiagnosticResult.CompilerError("CS0103").WithSpan(11, 9, 11, 16).WithArguments("Console"), + source); + } + + [Fact] + public async Task DoRemoveCastOnCallToMethodWithInvalidParamsArgs() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class Program { + public static void Main(string[] args) + { + TakesParams([|(string)|]null); + } + + private static void TakesParams({|CS0225:params|} string wrongDefined) + { + } } - } - """, - """ - class Program - { - public static void Main(string[] args) + """, + """ + class Program { - TakesParams(null); + public static void Main(string[] args) + { + TakesParams(null); + } + + private static void TakesParams({|CS0225:params|} string wrongDefined) + { + } } + """); + } - private static void TakesParams({|CS0225:params|} string wrongDefined) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/18978")] + public async Task RemoveCastOnCallToMethodWithParamsArgsIfImplicitConversionExists() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class Program { - } - } - """); - } + public static void Main(string[] args) + { + var takesArgs = new[] { "Hello", "World" }; + TakesParams([|(System.IComparable[])|]takesArgs); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/18978")] - public async Task RemoveCastOnCallToMethodWithParamsArgsIfImplicitConversionExists() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class Program - { - public static void Main(string[] args) + private static void TakesParams(params object[] goo) + { + System.Console.WriteLine(goo.Length); + } + } + """, + """ + class Program { - var takesArgs = new[] { "Hello", "World" }; - TakesParams([|(System.IComparable[])|]takesArgs); + public static void Main(string[] args) + { + var takesArgs = new[] { "Hello", "World" }; + TakesParams(takesArgs); + } + + private static void TakesParams(params object[] goo) + { + System.Console.WriteLine(goo.Length); + } } + """); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20630")] + public async Task DoNotRemoveCastOnCallToAttributeWithParamsArgs() + { + var source = + """ + using System; + using System.Reflection; - private static void TakesParams(params object[] goo) + sealed class MarkAttribute : Attribute { - System.Console.WriteLine(goo.Length); + public readonly string[] Arr; + + public MarkAttribute(params string[] arr) + { + Arr = arr; + } } - } - """, - """ - class Program - { - public static void Main(string[] args) + [Mark((string)null)] // wrong instance of: IDE0004 Cast is redundant. + static class Program { - var takesArgs = new[] { "Hello", "World" }; - TakesParams(takesArgs); + static void Main() + { + } } + """; + + await VerifyCS.VerifyCodeFixAsync(source, source); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/29264")] + public async Task DoNotRemoveCastOnDictionaryIndexer() + { + var source = + """ + using System; + using System.Reflection; + using System.Collections.Generic; - private static void TakesParams(params object[] goo) + static class Program { - System.Console.WriteLine(goo.Length); + enum TestEnum + { + Test, + } + + static void Main() + { + Dictionary Icons = new Dictionary + { + [(int) TestEnum.Test] = null, + }; + } } - } - """); - } + """; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20630")] - public async Task DoNotRemoveCastOnCallToAttributeWithParamsArgs() - { - var source = - """ - using System; - using System.Reflection; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - sealed class MarkAttribute : Attribute - { - public readonly string[] Arr; - - public MarkAttribute(params string[] arr) - { - Arr = arr; - } - } - [Mark((string)null)] // wrong instance of: IDE0004 Cast is redundant. - static class Program - { - static void Main() - { - } - } - """; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/29264")] + public async Task RemoveCastOnDictionaryIndexer() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + using System.Reflection; + using System.Collections.Generic; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + static class Program + { + enum TestEnum + { + Test, + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/29264")] - public async Task DoNotRemoveCastOnDictionaryIndexer() - { - var source = - """ - using System; - using System.Reflection; - using System.Collections.Generic; + static void Main() + { + Dictionary Icons = new Dictionary + { + [[|(int)|] 0] = null, + }; + } + } + """, + """ + using System; + using System.Reflection; + using System.Collections.Generic; - static class Program - { - enum TestEnum + static class Program { - Test, + enum TestEnum + { + Test, + } + + static void Main() + { + Dictionary Icons = new Dictionary + { + [0] = null, + }; + } } + """); + } - static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20630")] + public async Task DoNotRemoveCastOnCallToAttributeWithParamsArgsAndProperty() + { + var source = + """ + using System; + sealed class MarkAttribute : Attribute { - Dictionary Icons = new Dictionary + public MarkAttribute(params string[] arr) { - [(int) TestEnum.Test] = null, - }; + } + public int Prop { get; set; } } - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/29264")] - public async Task RemoveCastOnDictionaryIndexer() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - using System.Reflection; - using System.Collections.Generic; - - static class Program - { - enum TestEnum + [Mark((string)null, Prop = 1)] + static class Program { - Test, } + """; + + await VerifyCS.VerifyCodeFixAsync(source, source); + } - static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20630")] + public async Task DoNotRemoveCastOnCallToAttributeWithParamsArgsPropertyAndOtherArg() + { + var source = + """ + using System; + sealed class MarkAttribute : Attribute { - Dictionary Icons = new Dictionary + public MarkAttribute(bool otherArg, params string[] arr) { - [[|(int)|] 0] = null, - }; + } + public int Prop { get; set; } } - } - """, - """ - using System; - using System.Reflection; - using System.Collections.Generic; - static class Program - { - enum TestEnum + [Mark(true, (string)null, Prop = 1)] + static class Program { - Test, } + """; - static void Main() + await VerifyCS.VerifyCodeFixAsync(source, source); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20630")] + public async Task DoNotRemoveCastOnCallToAttributeWithParamsArgsNamedArgsAndProperty() + { + var source = + """ + using System; + sealed class MarkAttribute : Attribute { - Dictionary Icons = new Dictionary + public MarkAttribute(bool otherArg, params string[] arr) { - [0] = null, - }; + } + public int Prop { get; set; } } - } - """); - } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20630")] - public async Task DoNotRemoveCastOnCallToAttributeWithParamsArgsAndProperty() - { - var source = - """ - using System; - sealed class MarkAttribute : Attribute - { - public MarkAttribute(params string[] arr) + [Mark(arr: (string)null, otherArg: true, Prop = 1)] + static class Program { } - public int Prop { get; set; } - } - - [Mark((string)null, Prop = 1)] - static class Program - { - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20630")] - public async Task DoNotRemoveCastOnCallToAttributeWithParamsArgsPropertyAndOtherArg() - { - var source = - """ - using System; - sealed class MarkAttribute : Attribute - { - public MarkAttribute(bool otherArg, params string[] arr) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20630")] + public async Task DoRemoveCastOnCallToAttributeWithInvalidParamsArgs() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + sealed class MarkAttribute : Attribute { + public MarkAttribute(bool otherArg, {|CS0225:params|} string wrongDefined) + { + } + public int Prop { get; set; } } - public int Prop { get; set; } - } - [Mark(true, (string)null, Prop = 1)] - static class Program - { - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20630")] - public async Task DoNotRemoveCastOnCallToAttributeWithParamsArgsNamedArgsAndProperty() - { - var source = - """ - using System; - sealed class MarkAttribute : Attribute - { - public MarkAttribute(bool otherArg, params string[] arr) + [Mark(true, [|(string)|]null, Prop = 1)] + static class Program { } - public int Prop { get; set; } - } - - [Mark(arr: (string)null, otherArg: true, Prop = 1)] - static class Program - { - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20630")] - public async Task DoRemoveCastOnCallToAttributeWithInvalidParamsArgs() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - sealed class MarkAttribute : Attribute - { - public MarkAttribute(bool otherArg, {|CS0225:params|} string wrongDefined) + """, + """ + using System; + sealed class MarkAttribute : Attribute { + public MarkAttribute(bool otherArg, {|CS0225:params|} string wrongDefined) + { + } + public int Prop { get; set; } } - public int Prop { get; set; } - } - [Mark(true, [|(string)|]null, Prop = 1)] - static class Program - { - } - """, - """ - using System; - sealed class MarkAttribute : Attribute - { - public MarkAttribute(bool otherArg, {|CS0225:params|} string wrongDefined) + [Mark(true, null, Prop = 1)] + static class Program { } - public int Prop { get; set; } - } - - [Mark(true, null, Prop = 1)] - static class Program - { - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20630")] - public async Task RemoveCastOnCallToAttributeWithParamsArgsWithImplicitCast() - { - var source = - """ - using System; - sealed class MarkAttribute : Attribute - { - public MarkAttribute(bool otherArg, params object[] arr) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20630")] + public async Task RemoveCastOnCallToAttributeWithParamsArgsWithImplicitCast() + { + var source = + """ + using System; + sealed class MarkAttribute : Attribute { + public MarkAttribute(bool otherArg, params object[] arr) + { + } + public int Prop { get; set; } } - public int Prop { get; set; } - } - [Mark(arr: [|(object[])|]new[] { "Hello", "World" }, otherArg: true, Prop = 1)] - static class Program - { - } - """; - var fixedSource = - """ - using System; - sealed class MarkAttribute : Attribute - { - public MarkAttribute(bool otherArg, params object[] arr) + [Mark(arr: [|(object[])|]new[] { "Hello", "World" }, otherArg: true, Prop = 1)] + static class Program + { + } + """; + var fixedSource = + """ + using System; + sealed class MarkAttribute : Attribute { + public MarkAttribute(bool otherArg, params object[] arr) + { + } + public int Prop { get; set; } } - public int Prop { get; set; } - } - [Mark(arr: (new[] { "Hello", "World" }), otherArg: true, Prop = 1)] - static class Program - { - } - """; + [Mark(arr: (new[] { "Hello", "World" }), otherArg: true, Prop = 1)] + static class Program + { + } + """; - await new VerifyCS.Test - { - TestState = + await new VerifyCS.Test { - Sources = { source }, - ExpectedDiagnostics = + TestState = { - // /0/Test0.cs(11,2): error CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type - DiagnosticResult.CompilerError("CS0182").WithSpan(10, 2, 10, 75), + Sources = { source }, + ExpectedDiagnostics = + { + // /0/Test0.cs(11,2): error CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type + DiagnosticResult.CompilerError("CS0182").WithSpan(10, 2, 10, 75), + }, }, - }, - FixedState = - { - Sources = { fixedSource }, - ExpectedDiagnostics = + FixedState = { - // /0/Test0.cs(11,2): error CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type - DiagnosticResult.CompilerError("CS0182").WithSpan(10, 2, 10, 67), + Sources = { fixedSource }, + ExpectedDiagnostics = + { + // /0/Test0.cs(11,2): error CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type + DiagnosticResult.CompilerError("CS0182").WithSpan(10, 2, 10, 67), + }, }, - }, - }.RunAsync(); - } + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20630")] - public async Task RemoveCastOnCallToAttributeWithCastInPropertySetter() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - sealed class MarkAttribute : Attribute - { - public MarkAttribute() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20630")] + public async Task RemoveCastOnCallToAttributeWithCastInPropertySetter() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + sealed class MarkAttribute : Attribute { + public MarkAttribute() + { + } + public int Prop { get; set; } } - public int Prop { get; set; } - } - [Mark(Prop = [|(int)|]1)] - static class Program - { - } - """, - """ - using System; - sealed class MarkAttribute : Attribute - { - public MarkAttribute() + [Mark(Prop = [|(int)|]1)] + static class Program + { + } + """, + """ + using System; + sealed class MarkAttribute : Attribute { + public MarkAttribute() + { + } + public int Prop { get; set; } } - public int Prop { get; set; } - } - [Mark(Prop = 1)] - static class Program - { - } - """); - } + [Mark(Prop = 1)] + static class Program + { + } + """); + } - [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/18510")] - [InlineData("-")] - [InlineData("+")] - public async Task DoNotRemoveCastOnInvalidUnaryOperatorEnumValue1(string op) - { - var source = + [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/18510")] + [InlineData("-")] + [InlineData("+")] + public async Task DoNotRemoveCastOnInvalidUnaryOperatorEnumValue1(string op) + { + var source = $@" enum Sign {{ @@ -5606,15 +5606,15 @@ void Goo() }} }}"; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/18510")] - [InlineData("-")] - [InlineData("+")] - public async Task DoNotRemoveCastOnInvalidUnaryOperatorEnumValue2(string op) - { - var source = + [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/18510")] + [InlineData("-")] + [InlineData("+")] + public async Task DoNotRemoveCastOnInvalidUnaryOperatorEnumValue2(string op) + { + var source = $@" enum Sign {{ @@ -5631,15 +5631,65 @@ void Goo() }} }}"; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/18510")] - public async Task RemoveCastOnValidUnaryOperatorEnumValue() - { - var source = - """ - enum Sign + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/18510")] + public async Task RemoveCastOnValidUnaryOperatorEnumValue() + { + var source = + """ + enum Sign + { + Positive = 1, + Negative = -1 + } + + class T + { + void Goo() + { + Sign mySign = Sign.Positive; + Sign invertedSign = (Sign) ( ~[|(int)|] mySign ); + } + } + """; + var fixedSource = + """ + enum Sign + { + Positive = 1, + Negative = -1 + } + + class T + { + void Goo() + { + Sign mySign = Sign.Positive; + Sign invertedSign = [|(Sign)|] ( ~mySign); + } + } + """; + + await new VerifyCS.Test + { + TestCode = source, + FixedState = + { + Sources = { fixedSource }, + MarkupHandling = MarkupMode.Allow, + }, + CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne, + }.RunAsync(); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/18510")] + public async Task RemoveCastOnValidUnaryOperatorEnumValue_Nullable() + { + var source = + """ + enum Sign { Positive = 1, Negative = -1 @@ -5650,13 +5700,13 @@ class T void Goo() { Sign mySign = Sign.Positive; - Sign invertedSign = (Sign) ( ~[|(int)|] mySign ); + Sign? invertedSign = (Sign?)(~[|(int)|] mySign); } } - """; - var fixedSource = - """ - enum Sign + """; + var fixedSource = + """ + enum Sign { Positive = 1, Negative = -1 @@ -5667,7347 +5717,7297 @@ class T void Goo() { Sign mySign = Sign.Positive; - Sign invertedSign = [|(Sign)|] ( ~mySign); + Sign? invertedSign = (Sign?)(~mySign); } } - """; + """; - await new VerifyCS.Test - { - TestCode = source, - FixedState = + await new VerifyCS.Test { - Sources = { fixedSource }, - MarkupHandling = MarkupMode.Allow, - }, - CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne, - }.RunAsync(); - } + TestCode = source, + FixedCode = fixedSource, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/18510")] - public async Task RemoveCastOnValidUnaryOperatorEnumValue_Nullable() - { - var source = - """ - enum Sign - { - Positive = 1, - Negative = -1 - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/18510")] + public async Task DoNotRemoveEnumCastToDifferentRepresentation() + { + var source = + """ + enum Sign + { + Positive = 1, + Negative = -1 + } - class T - { - void Goo() - { - Sign mySign = Sign.Positive; - Sign? invertedSign = (Sign?)(~[|(int)|] mySign); - } - } - """; - var fixedSource = - """ - enum Sign - { - Positive = 1, - Negative = -1 - } + class T + { + void Goo() + { + Sign mySign = Sign.Positive; + Sign invertedSign = (Sign) ( ~(long) mySign ); + } + } + """; - class T + await new VerifyCS.Test { - void Goo() - { - Sign mySign = Sign.Positive; - Sign? invertedSign = (Sign?)(~mySign); - } - } - """; + TestCode = source, + FixedCode = source, + }.RunAsync(); + } - await new VerifyCS.Test + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25456#issuecomment-373549735")] + public async Task DoNotIntroduceDefaultLiteralInSwitchCase() { - TestCode = source, - FixedCode = fixedSource, - }.RunAsync(); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/18510")] - public async Task DoNotRemoveEnumCastToDifferentRepresentation() - { - var source = - """ - enum Sign + var source = + """ + class C { - Positive = 1, - Negative = -1 + void M() + { + switch (true) + { + case (bool)default: + break; + } + } } + """; - class T + await new VerifyCS.Test + { + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp7_1, + }.RunAsync(); + } + + [Fact] + public async Task DoNotIntroduceDefaultLiteralInSwitchCase_CastInsideParentheses() + { + var source = + """ + class C { - void Goo() + void M() { - Sign mySign = Sign.Positive; - Sign invertedSign = (Sign) ( ~(long) mySign ); + switch (true) + { + case ((bool)default): + break; + } } } - """; - - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - }.RunAsync(); - } + """; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25456#issuecomment-373549735")] - public async Task DoNotIntroduceDefaultLiteralInSwitchCase() - { - var source = - """ - class C + await new VerifyCS.Test { - void M() + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp7_1, + }.RunAsync(); + } + + [Fact] + public async Task DoNotIntroduceDefaultLiteralInSwitchCase_DefaultInsideParentheses() + { + var source = + """ + class C { - switch (true) + void M() { - case (bool)default: - break; + switch (true) + { + case (bool)(default): + break; + } } } - } - """; + """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp7_1, - }.RunAsync(); - } - - [Fact] - public async Task DoNotIntroduceDefaultLiteralInSwitchCase_CastInsideParentheses() - { - var source = - """ - class C + await new VerifyCS.Test { - void M() + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp7_1, + }.RunAsync(); + } + + [Fact] + public async Task DoNotIntroduceDefaultLiteralInSwitchCase_RemoveDoubleCast() + { + var source = + """ + class C { - switch (true) + void M() { - case ((bool)default): - break; + switch (true) + { + case [|(bool)|][|(bool)|]default: + break; + } } } - } - """; - - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp7_1, - }.RunAsync(); - } - - [Fact] - public async Task DoNotIntroduceDefaultLiteralInSwitchCase_DefaultInsideParentheses() - { - var source = - """ - class C - { - void M() + """; + var fixedSource = + """ + class C { - switch (true) + void M() { - case (bool)(default): - break; + switch (true) + { + case (bool)default: + break; + } } } - } - """; - - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp7_1, - }.RunAsync(); - } + """; - [Fact] - public async Task DoNotIntroduceDefaultLiteralInSwitchCase_RemoveDoubleCast() - { - var source = - """ - class C + await new VerifyCS.Test { - void M() + TestCode = source, + FixedCode = fixedSource, + LanguageVersion = LanguageVersion.CSharp7_1, + }.RunAsync(); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/12631")] + public async Task RemoveRedundantBoolCast() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class C { - switch (true) + void M() { - case [|(bool)|][|(bool)|]default: - break; + var a = true; + var b = ![|(bool)|]a; } } - } - """; - var fixedSource = - """ - class C - { - void M() + """, + """ + class C { - switch (true) + void M() { - case (bool)default: - break; + var a = true; + var b = !a; } } - } - """; + """); + } - await new VerifyCS.Test + [Fact] + public async Task DoNotIntroduceDefaultLiteralInPatternSwitchCase() { - TestCode = source, - FixedCode = fixedSource, - LanguageVersion = LanguageVersion.CSharp7_1, - }.RunAsync(); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/12631")] - public async Task RemoveRedundantBoolCast() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class C - { - void M() + var source = + """ + class C { - var a = true; - var b = ![|(bool)|]a; + void M() + { + switch (true) + { + case (bool)default when true: + break; + } + } } - } - """, - """ - class C + """; + + await new VerifyCS.Test { - void M() + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp7_1, + }.RunAsync(); + } + + [Fact] + public async Task DoNotIntroduceDefaultLiteralInPatternSwitchCase_CastInsideParentheses() + { + var source = + """ + class C { - var a = true; - var b = !a; + void M() + { + switch (true) + { + case ((bool)default) when true: + break; + } + } } - } - """); - } + """; - [Fact] - public async Task DoNotIntroduceDefaultLiteralInPatternSwitchCase() - { - var source = - """ - class C + await new VerifyCS.Test { - void M() + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp7_1, + }.RunAsync(); + } + + [Fact] + public async Task DoNotIntroduceDefaultLiteralInPatternSwitchCase_DefaultInsideParentheses() + { + var source = + """ + class C { - switch (true) + void M() { - case (bool)default when true: - break; + switch (true) + { + case (bool)(default) when true: + break; + } } } - } - """; - - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp7_1, - }.RunAsync(); - } + """; - [Fact] - public async Task DoNotIntroduceDefaultLiteralInPatternSwitchCase_CastInsideParentheses() - { - var source = - """ - class C + await new VerifyCS.Test { - void M() + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp7_1, + }.RunAsync(); + } + + [Fact] + public async Task DoNotIntroduceDefaultLiteralInPatternSwitchCase_RemoveDoubleCast() + { + var source = + """ + class C { - switch (true) + void M() { - case ((bool)default) when true: - break; + switch (true) + { + case [|(bool)|][|(bool)|]default when true: + break; + } } } - } - """; - - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp7_1, - }.RunAsync(); - } - - [Fact] - public async Task DoNotIntroduceDefaultLiteralInPatternSwitchCase_DefaultInsideParentheses() - { - var source = - """ - class C - { - void M() + """; + var fixedSource = + """ + class C { - switch (true) + void M() { - case (bool)(default) when true: - break; + switch (true) + { + case (bool)default when true: + break; + } } } - } - """; + """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp7_1, - }.RunAsync(); - } - - [Fact] - public async Task DoNotIntroduceDefaultLiteralInPatternSwitchCase_RemoveDoubleCast() - { - var source = - """ - class C + await new VerifyCS.Test { - void M() + TestCode = source, + FixedCode = fixedSource, + LanguageVersion = LanguageVersion.CSharp7_1, + }.RunAsync(); + } + + [Fact] + public async Task DoNotIntroduceDefaultLiteralInPatternSwitchCase_RemoveInsideWhenClause() + { + var source = + """ + class C { - switch (true) + void M() { - case [|(bool)|][|(bool)|]default when true: - break; + switch (true) + { + case (bool)default when [|(bool)|]default: + break; + } } } - } - """; - var fixedSource = - """ - class C - { - void M() + """; + var fixedSource = + """ + class C { - switch (true) + void M() { - case (bool)default when true: - break; + switch (true) + { + case (bool)default when default: + break; + } } } - } - """; - - await new VerifyCS.Test - { - TestCode = source, - FixedCode = fixedSource, - LanguageVersion = LanguageVersion.CSharp7_1, - }.RunAsync(); - } + """; - [Fact] - public async Task DoNotIntroduceDefaultLiteralInPatternSwitchCase_RemoveInsideWhenClause() - { - var source = - """ - class C + await new VerifyCS.Test { - void M() + TestCode = source, + FixedCode = fixedSource, + LanguageVersion = LanguageVersion.CSharp7_1, + }.RunAsync(); + } + + [Fact] + public async Task DoNotIntroduceDefaultLiteralInPatternIs() + { + var source = + """ + class C { - switch (true) + void M() { - case (bool)default when [|(bool)|]default: - break; + if (true is (bool)default); } } - } - """; - var fixedSource = - """ - class C + """; + + await new VerifyCS.Test { - void M() + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp7_1, + }.RunAsync(); + } + + [Fact] + public async Task DoNotIntroduceDefaultLiteralInPatternIs_CastInsideParentheses() + { + var source = + """ + class C { - switch (true) + void M() { - case (bool)default when default: - break; + if (true is ((bool)default)); } } - } - """; + """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = fixedSource, - LanguageVersion = LanguageVersion.CSharp7_1, - }.RunAsync(); - } - - [Fact] - public async Task DoNotIntroduceDefaultLiteralInPatternIs() - { - var source = - """ - class C + await new VerifyCS.Test { - void M() - { - if (true is (bool)default); - } - } - """; + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp7_1, + }.RunAsync(); + } - await new VerifyCS.Test + [Fact] + public async Task DoNotIntroduceDefaultLiteralInPatternIs_DefaultInsideParentheses() { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp7_1, - }.RunAsync(); - } - - [Fact] - public async Task DoNotIntroduceDefaultLiteralInPatternIs_CastInsideParentheses() - { - var source = - """ - class C - { - void M() + var source = + """ + class C { - if (true is ((bool)default)); + void M() + { + if (true is (bool)(default)); + } } - } - """; + """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp7_1, - }.RunAsync(); - } - - [Fact] - public async Task DoNotIntroduceDefaultLiteralInPatternIs_DefaultInsideParentheses() - { - var source = - """ - class C + await new VerifyCS.Test { - void M() - { - if (true is (bool)(default)); - } - } - """; + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp7_1, + }.RunAsync(); + } - await new VerifyCS.Test + [Fact] + public async Task DoNotIntroduceDefaultLiteralInPatternIs_RemoveDoubleCast() { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp7_1, - }.RunAsync(); - } - - [Fact] - public async Task DoNotIntroduceDefaultLiteralInPatternIs_RemoveDoubleCast() - { - var source = - """ - class C - { - void M() + var source = + """ + class C { - if (true is [|(bool)|][|(bool)|]default); + void M() + { + if (true is [|(bool)|][|(bool)|]default); + } } - } - """; - var fixedSource = - """ - class C - { - void M() + """; + var fixedSource = + """ + class C { - if (true is (bool)default) ; + void M() + { + if (true is (bool)default) ; + } } - } - """; - - await new VerifyCS.Test - { - TestCode = source, - FixedCode = fixedSource, - LanguageVersion = LanguageVersion.CSharp7_1, - }.RunAsync(); - } + """; - [Fact] - public async Task DoNotIntroduceDefaultLiteralInPropertyPattern1() - { - var source = - """ - class C + await new VerifyCS.Test { - void M(string s) + TestCode = source, + FixedCode = fixedSource, + LanguageVersion = LanguageVersion.CSharp7_1, + }.RunAsync(); + } + + [Fact] + public async Task DoNotIntroduceDefaultLiteralInPropertyPattern1() + { + var source = + """ + class C { - if (s is { Length: (int)default }) + void M(string s) { + if (s is { Length: (int)default }) + { + } } } - } - """; - - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + """; - [Fact] - public async Task DoNotIntroduceDefaultLiteralInPropertyPattern2() - { - var source = - """ - class C + await new VerifyCS.Test { - void M(string s) + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } + + [Fact] + public async Task DoNotIntroduceDefaultLiteralInPropertyPattern2() + { + var source = + """ + class C { - if (s is { Length: ((int)default) }) + void M(string s) { + if (s is { Length: ((int)default) }) + { + } } } - } - """; + """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + await new VerifyCS.Test + { + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/27239")] - public async Task DoNotOfferToRemoveCastWhereNoConversionExists() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/27239")] + public async Task DoNotOfferToRemoveCastWhereNoConversionExists() + { + var source = + """ + using System; - class C - { - void M() + class C { - object o = null; - TypedReference r2 = {|CS0030:(TypedReference)o|}; + void M() + { + object o = null; + TypedReference r2 = {|CS0030:(TypedReference)o|}; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28412")] - public async Task DoNotOfferToRemoveCastWhenAccessingHiddenProperty() - { - var source = """ - using System.Collections.Generic; - class Fruit - { - public IDictionary Properties { get; set; } - } - class Apple : Fruit - { - public new IDictionary Properties { get; } - } - class Tester - { - public void Test() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28412")] + public async Task DoNotOfferToRemoveCastWhenAccessingHiddenProperty() + { + var source = """ + using System.Collections.Generic; + class Fruit { - var a = new Apple(); - ((Fruit)a).Properties["Color"] = "Red"; + public IDictionary Properties { get; set; } } - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/31963")] - public async Task DoNotOfferToRemoveCastInConstructorWhenItNeeded() - { - var source = """ - class IntegerWrapper - { - public IntegerWrapper(int value) + class Apple : Fruit { + public new IDictionary Properties { get; } } - } - enum Goo - { - First, - Second - } - class Tester - { - public void Test() + class Tester { - var a = new IntegerWrapper((int)Goo.First); + public void Test() + { + var a = new Apple(); + ((Fruit)a).Properties["Color"] = "Red"; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/31963")] - public async Task DoNotOfferToRemoveCastInBaseConstructorInitializerWhenItNeeded() - { - var source = - """ - class B - { - B(int a) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/31963")] + public async Task DoNotOfferToRemoveCastInConstructorWhenItNeeded() + { + var source = """ + class IntegerWrapper { + public IntegerWrapper(int value) + { + } } - } - class C : B - { - C(double a) : base((int)a) + enum Goo + { + First, + Second + } + class Tester { + public void Test() + { + var a = new IntegerWrapper((int)Goo.First); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync( - source, - // /0/Test0.cs(10,19): error CS0122: 'B.B(int)' is inaccessible due to its protection level - DiagnosticResult.CompilerError("CS0122").WithSpan(9, 19, 9, 23).WithArguments("B.B(int)"), - source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/31963")] - public async Task DoNotOfferToRemoveCastInConstructorInitializerWhenItNeeded() - { - var source = - """ - class B - { - B(int a) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/31963")] + public async Task DoNotOfferToRemoveCastInBaseConstructorInitializerWhenItNeeded() + { + var source = + """ + class B { + B(int a) + { + } } - - B(double a) : this((int)a) + class C : B { + C(double a) : base((int)a) + { + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/10220")] - public async Task DoNotRemoveObjectCastInParamsCall() - { - var source = - """ - using System; - using System.Diagnostics; + await VerifyCS.VerifyCodeFixAsync( + source, + // /0/Test0.cs(10,19): error CS0122: 'B.B(int)' is inaccessible due to its protection level + DiagnosticResult.CompilerError("CS0122").WithSpan(9, 19, 9, 23).WithArguments("B.B(int)"), + source); + } - class Program - { - static void Main(string[] args) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/31963")] + public async Task DoNotOfferToRemoveCastInConstructorInitializerWhenItNeeded() + { + var source = + """ + class B { - object[] arr = { 1, 2, 3 }; - testParams((object)arr); - } + B(int a) + { + } - static void testParams(params object[] ps) - { - Console.WriteLine(ps.Length); + B(double a) : this((int)a) + { + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22804")] - public async Task DoNotRemoveCastFromNullableToUnderlyingType() - { - var source = - """ - using System.Text; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/10220")] + public async Task DoNotRemoveObjectCastInParamsCall() + { + var source = + """ + using System; + using System.Diagnostics; - class C - { - private void M() + class Program { - StringBuilder numbers = new StringBuilder(); - int?[] position = new int?[2]; - numbers[(int)position[1]] = 'x'; + static void Main(string[] args) + { + object[] arr = { 1, 2, 3 }; + testParams((object)arr); + } + + static void testParams(params object[] ps) + { + Console.WriteLine(ps.Length); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41433")] - public async Task DoNotRemoveCastFromIntPtrToPointer() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22804")] + public async Task DoNotRemoveCastFromNullableToUnderlyingType() + { + var source = + """ + using System.Text; - class C - { - unsafe int Test(IntPtr safePointer) + class C { - return ((int*)safePointer)[0]; + private void M() + { + StringBuilder numbers = new StringBuilder(); + int?[] position = new int?[2]; + numbers[(int)position[1]] = 'x'; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/38599")] - public async Task DoNotRemoveCastFromIntPtrToPointerInReturn() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41433")] + public async Task DoNotRemoveCastFromIntPtrToPointer() + { + var source = + """ + using System; - class Program - { - public static unsafe int Read(IntPtr pointer, int offset) + class C { - return ((int*)pointer)[offset]; + unsafe int Test(IntPtr safePointer) + { + return ((int*)safePointer)[0]; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/32491")] - public async Task DoNotRemoveCastFromIntPtrToPointerWithTypeParameter() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/38599")] + public async Task DoNotRemoveCastFromIntPtrToPointerInReturn() + { + var source = + """ + using System; - struct Block - where T : unmanaged - { - IntPtr m_ptr; - unsafe ref T GetRef( int index ) + class Program { - return ref ((T*)m_ptr)[index]; + public static unsafe int Read(IntPtr pointer, int offset) + { + return ((int*)pointer)[offset]; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25021")] - public async Task DoNotRemoveCastFromIntPtrToPointerWithAddressAndCast() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/32491")] + public async Task DoNotRemoveCastFromIntPtrToPointerWithTypeParameter() + { + var source = + """ + using System; - class C - { - private unsafe void goo() + struct Block + where T : unmanaged { - var address = IntPtr.Zero; - var bar = (int*)&((long*)address)[10]; + IntPtr m_ptr; + unsafe ref T GetRef( int index ) + { + return ref ((T*)m_ptr)[index]; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/38347")] - public async Task TestArgToLocalFunction1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class Program - { - public static void M() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25021")] + public async Task DoNotRemoveCastFromIntPtrToPointerWithAddressAndCast() + { + var source = + """ + using System; + + class C + { + private unsafe void goo() + { + var address = IntPtr.Zero; + var bar = (int*)&((long*)address)[10]; + } + } + """; + + await VerifyCS.VerifyCodeFixAsync(source, source); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/38347")] + public async Task TestArgToLocalFunction1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class Program { - for (int i = 0; i < 1; i++) + public static void M() { - long a = 0, b = 0; + for (int i = 0; i < 1; i++) + { + long a = 0, b = 0; - SameScope([|(decimal)|]a + [|(decimal)|]b); + SameScope([|(decimal)|]a + [|(decimal)|]b); - static void SameScope(decimal sum) { } + static void SameScope(decimal sum) { } + } } } - } - """, - """ - class Program - { - public static void M() + """, + """ + class Program { - for (int i = 0; i < 1; i++) + public static void M() { - long a = 0, b = 0; + for (int i = 0; i < 1; i++) + { + long a = 0, b = 0; - SameScope(a + (decimal)b); + SameScope(a + (decimal)b); - static void SameScope(decimal sum) { } + static void SameScope(decimal sum) { } + } } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/38347")] - public async Task TestArgToLocalFunction2() - { - var source = - """ - class Program - { - public static void M() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/38347")] + public async Task TestArgToLocalFunction2() + { + var source = + """ + class Program { - for (int i = 0; i < 1; i++) + public static void M() { - long a = 0, b = 0; + for (int i = 0; i < 1; i++) + { + long a = 0, b = 0; - SameScope([|(decimal)|]a + [|(decimal)|]b); + SameScope([|(decimal)|]a + [|(decimal)|]b); - static void SameScope(decimal sum) { } + static void SameScope(decimal sum) { } + } } } - } - """; - var fixedSource = - """ - class Program - { - public static void M() + """; + var fixedSource = + """ + class Program { - for (int i = 0; i < 1; i++) + public static void M() { - long a = 0, b = 0; + for (int i = 0; i < 1; i++) + { + long a = 0, b = 0; - SameScope((decimal)a + b); + SameScope((decimal)a + b); - static void SameScope(decimal sum) { } + static void SameScope(decimal sum) { } + } } } - } - """; - var batchFixedSource = - """ - class Program - { - public static void M() + """; + var batchFixedSource = + """ + class Program { - for (int i = 0; i < 1; i++) + public static void M() { - long a = 0, b = 0; + for (int i = 0; i < 1; i++) + { + long a = 0, b = 0; - SameScope(a + (decimal)b); + SameScope(a + (decimal)b); - static void SameScope(decimal sum) { } + static void SameScope(decimal sum) { } + } } } - } - """; + """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = fixedSource, - BatchFixedCode = batchFixedSource, - CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne, - DiagnosticSelector = diagnostics => diagnostics[1], - }.RunAsync(); - } + await new VerifyCS.Test + { + TestCode = source, + FixedCode = fixedSource, + BatchFixedCode = batchFixedSource, + CodeFixTestBehaviors = CodeFixTestBehaviors.FixOne, + DiagnosticSelector = diagnostics => diagnostics[1], + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36631")] - public async Task TestFormattableString1() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36631")] + public async Task TestFormattableString1() + { + var source = + """ + using System; - class C - { - private void goo() + class C { - object x = (IFormattable)$""; + private void goo() + { + object x = (IFormattable)$""; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36631")] - public async Task TestFormattableString1_1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36631")] + public async Task TestFormattableString1_1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - class C - { - private void goo() + class C { - IFormattable x = [|(IFormattable)|]$""; + private void goo() + { + IFormattable x = [|(IFormattable)|]$""; + } } - } - """, - """ - using System; + """, + """ + using System; - class C - { - private void goo() + class C { - IFormattable x = $""; + private void goo() + { + IFormattable x = $""; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36631")] - public async Task TestFormattableString2() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36631")] + public async Task TestFormattableString2() + { + var source = + """ + using System; - class C - { - private void goo() + class C { - object x = (FormattableString)$""; + private void goo() + { + object x = (FormattableString)$""; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36631")] - public async Task TestFormattableString2_2() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36631")] + public async Task TestFormattableString2_2() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - class C - { - private void goo() + class C { - FormattableString x = [|(FormattableString)|]$""; + private void goo() + { + FormattableString x = [|(FormattableString)|]$""; + } } - } - """, - """ - using System; + """, + """ + using System; - class C - { - private void goo() + class C { - FormattableString x = $""; + private void goo() + { + FormattableString x = $""; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36631")] - public async Task TestFormattableString3() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36631")] + public async Task TestFormattableString3() + { + var source = + """ + using System; - class C - { - private void goo() + class C { - bar((FormattableString)$""); - } + private void goo() + { + bar((FormattableString)$""); + } - private void bar(string s) { } - private void bar(FormattableString s) { } - } - """; + private void bar(string s) { } + private void bar(FormattableString s) { } + } + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36631")] - public async Task TestFormattableString4() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36631")] + public async Task TestFormattableString4() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - class C - { - private void goo() + class C { - bar([|(FormattableString)|]$""); - } + private void goo() + { + bar([|(FormattableString)|]$""); + } - private void bar(FormattableString s) { } - } - """, - """ - using System; + private void bar(FormattableString s) { } + } + """, + """ + using System; - class C - { - private void goo() + class C { - bar($""); - } + private void goo() + { + bar($""); + } - private void bar(FormattableString s) { } - } - """); - } + private void bar(FormattableString s) { } + } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36631")] - public async Task TestFormattableString5() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36631")] + public async Task TestFormattableString5() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - class C - { - private void goo() + class C { - object o = [|(string)|]$""; + private void goo() + { + object o = [|(string)|]$""; + } } - } - """, - """ - using System; + """, + """ + using System; - class C - { - private void goo() + class C { - object o = $""; + private void goo() + { + object o = $""; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36631")] - public async Task TestFormattableString6() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36631")] + public async Task TestFormattableString6() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - class C - { - private void goo() + class C { - bar([|(IFormattable)|]$""); - } + private void goo() + { + bar([|(IFormattable)|]$""); + } - private void bar(IFormattable s) { } - } - """, - """ - using System; + private void bar(IFormattable s) { } + } + """, + """ + using System; - class C - { - private void goo() + class C { - bar($""); - } + private void goo() + { + bar($""); + } - private void bar(IFormattable s) { } - } - """); - } + private void bar(IFormattable s) { } + } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36631")] - public async Task TestFormattableString7() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36631")] + public async Task TestFormattableString7() + { + var source = + """ + using System; - class C - { - private void goo() + class C { - object x = (IFormattable)$@""; + private void goo() + { + object x = (IFormattable)$@""; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34326")] - public async Task TestMissingOnInterfaceCallOnNonSealedClass() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34326")] + public async Task TestMissingOnInterfaceCallOnNonSealedClass() + { + var source = + """ + using System; - public class DbContext : IDisposable - { - public void Dispose() + public class DbContext : IDisposable { - Console.WriteLine("Base called"); + public void Dispose() + { + Console.WriteLine("Base called"); + } } - } - public class MyContext : DbContext, IDisposable - { - void IDisposable.Dispose() + public class MyContext : DbContext, IDisposable { - Console.WriteLine("Derived called"); + void IDisposable.Dispose() + { + Console.WriteLine("Derived called"); + } } - } - - class C - { - private static readonly DbContext _dbContext = new MyContext(); - static void Main() + class C { - ((IDisposable)_dbContext).Dispose(); + private static readonly DbContext _dbContext = new MyContext(); + + static void Main() + { + ((IDisposable)_dbContext).Dispose(); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync( - source, - source); - } + await VerifyCS.VerifyCodeFixAsync( + source, + source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34326")] - public async Task TestMissingOnInterfaceCallOnNonReadOnlyStruct() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34326")] + public async Task TestMissingOnInterfaceCallOnNonReadOnlyStruct() + { + var source = + """ + using System; - public struct DbContext : IDisposable - { - public int DisposeCount; - public void Dispose() + public struct DbContext : IDisposable { - DisposeCount++; + public int DisposeCount; + public void Dispose() + { + DisposeCount++; + } } - } - - class C - { - private static DbContext _dbContext = default; - static void Main() + class C { - ((IDisposable)_dbContext).Dispose(); + private static DbContext _dbContext = default; + + static void Main() + { + ((IDisposable)_dbContext).Dispose(); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync( - source, - source); - } + await VerifyCS.VerifyCodeFixAsync( + source, + source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34326")] - public async Task TestMissingOnInterfaceCallOnReadOnlyStruct() - { - // We technically could support this. But we choose not to for simplicity. While semantics could be - // preserved, the semantics around interfaces are subtle and we don't want to make a change that might - // negatively impact the user if they make other code changes. - var source = - """ - using System; - - public struct DbContext : IDisposable - { - public int DisposeCount; - public void Dispose() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34326")] + public async Task TestMissingOnInterfaceCallOnReadOnlyStruct() + { + // We technically could support this. But we choose not to for simplicity. While semantics could be + // preserved, the semantics around interfaces are subtle and we don't want to make a change that might + // negatively impact the user if they make other code changes. + var source = + """ + using System; + + public struct DbContext : IDisposable { - DisposeCount++; + public int DisposeCount; + public void Dispose() + { + DisposeCount++; + } } - } - class C - { - private static readonly DbContext _dbContext = default; - - static void Main() + class C { - ((IDisposable)_dbContext).Dispose(); + private static readonly DbContext _dbContext = default; + + static void Main() + { + ((IDisposable)_dbContext).Dispose(); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync( - source, - source); - } + await VerifyCS.VerifyCodeFixAsync( + source, + source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34326")] - public async Task TestOnInterfaceCallOnSealedClass() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34326")] + public async Task TestOnInterfaceCallOnSealedClass() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - public sealed class DbContext : IDisposable - { - public void Dispose() + public sealed class DbContext : IDisposable { - Console.WriteLine("Base called"); + public void Dispose() + { + Console.WriteLine("Base called"); + } } - } - - class C - { - private readonly DbContext _dbContext = null; - void Main() + class C { - ([|(IDisposable)|]_dbContext).Dispose(); + private readonly DbContext _dbContext = null; + + void Main() + { + ([|(IDisposable)|]_dbContext).Dispose(); + } } - } - """, - """ - using System; + """, + """ + using System; - public sealed class DbContext : IDisposable - { - public void Dispose() + public sealed class DbContext : IDisposable { - Console.WriteLine("Base called"); + public void Dispose() + { + Console.WriteLine("Base called"); + } } - } - - class C - { - private readonly DbContext _dbContext = null; - void Main() + class C { - _dbContext.Dispose(); + private readonly DbContext _dbContext = null; + + void Main() + { + _dbContext.Dispose(); + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/29726")] - public async Task TestDefaultLiteralWithNullableCastInCoalesce() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/29726")] + public async Task TestDefaultLiteralWithNullableCastInCoalesce() + { + var source = + """ + using System; - public class C - { - public void Goo() + public class C { - int x = (int?)(int)default ?? 42; + public void Goo() + { + int x = (int?)(int)default ?? 42; + } } - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/6309")] - public async Task TestFPIdentityThatMustRemain1() - { - var source = - """ - using System; + """; - public class C - { - float X() => 2 / (float)X(); - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] - public async Task TestFPIdentityThatMustRemain2() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/6309")] + public async Task TestFPIdentityThatMustRemain1() + { + var source = + """ + using System; - public class C - { - void M() + public class C { - float f1 = 0.00000000002f; - float f2 = 1 / f1; - double d = (float)f2; + float X() => 2 / (float)X(); } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] - public async Task TestFPIdentityThatMustRemain3() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] + public async Task TestFPIdentityThatMustRemain2() + { + var source = + """ + using System; - public class C - { - void M() + public class C { - float f1 = 0.00000000002f; - float f2 = 1 / f1; - float f3 = (float)f2; + void M() + { + float f1 = 0.00000000002f; + float f2 = 1 / f1; + double d = (float)f2; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] - public async Task TestCanRemoveFPIdentityOnFieldRead() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - public class C - { - float f; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] + public async Task TestFPIdentityThatMustRemain3() + { + var source = + """ + using System; - void M() + public class C { - var v = [|(float)|]f; + void M() + { + float f1 = 0.00000000002f; + float f2 = 1 / f1; + float f3 = (float)f2; + } } - } - """, - """ - using System; + """; - public class C - { - float f; + await VerifyCS.VerifyCodeFixAsync(source, source); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] + public async Task TestCanRemoveFPIdentityOnFieldRead() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - void M() + public class C { - var v = f; - } - } - """); - } + float f; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] - public async Task TestCanRemoveFPIdentityOnFieldWrite() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - - public class C - { - float f; + void M() + { + var v = [|(float)|]f; + } + } + """, + """ + using System; - void M(float f1) + public class C { - f = [|(float)|]f1; + float f; + + void M() + { + var v = f; + } } - } - """, - """ - using System; + """); + } - public class C - { - float f; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] + public async Task TestCanRemoveFPIdentityOnFieldWrite() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - void M(float f1) + public class C { - f = f1; + float f; + + void M(float f1) + { + f = [|(float)|]f1; + } } - } - """); - } + """, + """ + using System; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] - public async Task TestCanRemoveFPIdentityInFieldInitializer() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + public class C + { + float f; - public class C - { - static float f1; - static float f2 = [|(float)|]f1; - } - """, - """ - using System; - - public class C - { - static float f1; - static float f2 = f1; - } - """); - } + void M(float f1) + { + f = f1; + } + } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] - public async Task TestCanRemoveFPIdentityOnArrayRead() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] + public async Task TestCanRemoveFPIdentityInFieldInitializer() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - public class C - { - float[] f; + public class C + { + static float f1; + static float f2 = [|(float)|]f1; + } + """, + """ + using System; - void M() + public class C { - var v = [|(float)|]f[0]; + static float f1; + static float f2 = f1; } - } - """, - """ - using System; + """); + } - public class C - { - float[] f; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] + public async Task TestCanRemoveFPIdentityOnArrayRead() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - void M() + public class C { - var v = f[0]; + float[] f; + + void M() + { + var v = [|(float)|]f[0]; + } } - } - """); - } + """, + """ + using System; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] - public async Task TestCanRemoveFPIdentityOnArrayWrite() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + public class C + { + float[] f; - public class C - { - float[] f; + void M() + { + var v = f[0]; + } + } + """); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] + public async Task TestCanRemoveFPIdentityOnArrayWrite() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - void M(float f2) + public class C { - f[0] = [|(float)|]f2; - } - } - """, - """ - using System; + float[] f; - public class C - { - float[] f; + void M(float f2) + { + f[0] = [|(float)|]f2; + } + } + """, + """ + using System; - void M(float f2) + public class C { - f[0] = f2; + float[] f; + + void M(float f2) + { + f[0] = f2; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] - public async Task TestCanRemoveFPIdentityOnArrayInitializer1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] + public async Task TestCanRemoveFPIdentityOnArrayInitializer1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - public class C - { - void M(float f2) + public class C { - float[] f = { [|(float)|]f2 }; + void M(float f2) + { + float[] f = { [|(float)|]f2 }; + } } - } - """, - """ - using System; + """, + """ + using System; - public class C - { - void M(float f2) + public class C { - float[] f = { f2 }; + void M(float f2) + { + float[] f = { f2 }; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] - public async Task TestCanRemoveFPIdentityOnArrayInitializer2() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] + public async Task TestCanRemoveFPIdentityOnArrayInitializer2() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - public class C - { - void M(float f2) + public class C { - float[] f = new float[] { [|(float)|]f2 }; + void M(float f2) + { + float[] f = new float[] { [|(float)|]f2 }; + } } - } - """, - """ - using System; + """, + """ + using System; - public class C - { - void M(float f2) + public class C { - float[] f = new float[] { f2 }; + void M(float f2) + { + float[] f = new float[] { f2 }; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] - public async Task TestCanRemoveFPIdentityOnImplicitArrayInitializer() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] + public async Task TestCanRemoveFPIdentityOnImplicitArrayInitializer() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - public class C - { - void M(float f2) + public class C { - float[] f = new[] { [|(float)|]f2 }; + void M(float f2) + { + float[] f = new[] { [|(float)|]f2 }; + } } - } - """, - """ - using System; + """, + """ + using System; - public class C - { - void M(float f2) + public class C { - float[] f = new[] { f2 }; + void M(float f2) + { + float[] f = new[] { f2 }; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] - public async Task TestCanRemoveFPWithBoxing1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] + public async Task TestCanRemoveFPWithBoxing1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - public class C - { - void M() + public class C { - float value = 0.0f; - object boxed = [|(float)|]value; + void M() + { + float value = 0.0f; + object boxed = [|(float)|]value; + } } - } - """, - """ - using System; + """, + """ + using System; - public class C - { - void M() + public class C { - float value = 0.0f; - object boxed = value; + void M() + { + float value = 0.0f; + object boxed = value; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] - public async Task TestCanRemoveFPWithBoxing2() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34873")] + public async Task TestCanRemoveFPWithBoxing2() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - public class C - { - void M() + public class C { - double value = 0.0; - object boxed = [|(double)|]value; + void M() + { + double value = 0.0; + object boxed = [|(double)|]value; + } } - } - """, - """ - using System; + """, + """ + using System; - public class C - { - void M() + public class C { - double value = 0.0; - object boxed = value; + void M() + { + double value = 0.0; + object boxed = value; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37953")] - public async Task TestCanRemoveFromUnnecessarySwitchExpressionCast1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37953")] + public async Task TestCanRemoveFromUnnecessarySwitchExpressionCast1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - class Program - { - public static void Main() { } + class Program + { + public static void Main() { } - public static string GetValue(DayOfWeek value) - => [|(DayOfWeek)|]value switch - { - DayOfWeek.Monday => "Monday", - _ => "Other", - }; - } - """, - """ - using System; + public static string GetValue(DayOfWeek value) + => [|(DayOfWeek)|]value switch + { + DayOfWeek.Monday => "Monday", + _ => "Other", + }; + } + """, + """ + using System; - class Program - { - public static void Main() { } + class Program + { + public static void Main() { } - public static string GetValue(DayOfWeek value) - => value switch - { - DayOfWeek.Monday => "Monday", - _ => "Other", - }; - } - """); - } + public static string GetValue(DayOfWeek value) + => value switch + { + DayOfWeek.Monday => "Monday", + _ => "Other", + }; + } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37953")] - public async Task TestLeaveNecessarySwitchExpressionCast1() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37953")] + public async Task TestLeaveNecessarySwitchExpressionCast1() + { + var source = + """ + using System; - class Program - { - public static void Main() { } + class Program + { + public static void Main() { } - public static string GetValue(int value) - => (DayOfWeek)value switch - { - DayOfWeek.Monday => "Monday", - _ => "Other", - }; - } - """; + public static string GetValue(int value) + => (DayOfWeek)value switch + { + DayOfWeek.Monday => "Monday", + _ => "Other", + }; + } + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithOrAssignment1() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithOrAssignment1() + { + var source = + """ + using System; - class C - { - private long Repro() + class C { - var random = new Random(); - long result = random.Next(); - result <<= 32; - result |= (long)random.Next(); - return result; + private long Repro() + { + var random = new Random(); + long result = random.Next(); + result <<= 32; + result |= (long)random.Next(); + return result; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithOrBinary1() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithOrBinary1() + { + var source = + """ + using System; - class C - { - private long Repro() + class C { - var random = new Random(); - long result = random.Next(); - result <<= 32; - var v = result | (long)random.Next(); - return result; + private long Repro() + { + var random = new Random(); + long result = random.Next(); + result <<= 32; + var v = result | (long)random.Next(); + return result; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithOrBinary2() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithOrBinary2() + { + var source = + """ + using System; - class C - { - private long Repro() + class C { - var random = new Random(); - long result = random.Next(); - result <<= 32; - var v = (long)random.Next() | result; - return result; + private long Repro() + { + var random = new Random(); + long result = random.Next(); + result <<= 32; + var v = (long)random.Next() | result; + return result; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithAndAssignment1() - { + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithAndAssignment1() + { - await VerifyCS.VerifyCodeFixAsync(""" - using System; + await VerifyCS.VerifyCodeFixAsync(""" + using System; - class C - { - private long Repro() + class C { - var random = new Random(); - long result = random.Next(); - result <<= 32; - result &= [|(long)|]random.Next(); - return result; + private long Repro() + { + var random = new Random(); + long result = random.Next(); + result <<= 32; + result &= [|(long)|]random.Next(); + return result; + } } - } - """, - """ - using System; + """, + """ + using System; - class C - { - private long Repro() + class C { - var random = new Random(); - long result = random.Next(); - result <<= 32; - result &= random.Next(); - return result; + private long Repro() + { + var random = new Random(); + long result = random.Next(); + result <<= 32; + result &= random.Next(); + return result; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithAndBinary1() - { + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithAndBinary1() + { - await VerifyCS.VerifyCodeFixAsync(""" - using System; + await VerifyCS.VerifyCodeFixAsync(""" + using System; - class C - { - private long Repro() + class C { - var random = new Random(); - long result = random.Next(); - result <<= 32; - var x = result & [|(long)|]random.Next(); - return result; + private long Repro() + { + var random = new Random(); + long result = random.Next(); + result <<= 32; + var x = result & [|(long)|]random.Next(); + return result; + } } - } - """, - """ - using System; + """, + """ + using System; - class C - { - private long Repro() + class C { - var random = new Random(); - long result = random.Next(); - result <<= 32; - var x = result & random.Next(); - return result; + private long Repro() + { + var random = new Random(); + long result = random.Next(); + result <<= 32; + var x = result & random.Next(); + return result; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithAndBinary2() - { + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithAndBinary2() + { - await VerifyCS.VerifyCodeFixAsync(""" - using System; + await VerifyCS.VerifyCodeFixAsync(""" + using System; - class C - { - private long Repro() + class C { - var random = new Random(); - long result = random.Next(); - result <<= 32; - var x = [|(long)|]random.Next() & result; - return result; + private long Repro() + { + var random = new Random(); + long result = random.Next(); + result <<= 32; + var x = [|(long)|]random.Next() & result; + return result; + } } - } - """, - """ - using System; + """, + """ + using System; - class C - { - private long Repro() + class C { - var random = new Random(); - long result = random.Next(); - result <<= 32; - var x = random.Next() & result; - return result; + private long Repro() + { + var random = new Random(); + long result = random.Next(); + result <<= 32; + var x = random.Next() & result; + return result; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithOrCompilerCase1() - { - var source = - """ - public class sign - { - public static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithOrCompilerCase1() + { + var source = + """ + public class sign { - int i32_hi = 1; - int i32_lo = 1; - ulong u64 = 1; - sbyte i08 = 1; - short i16 = -1; + public static void Main() + { + int i32_hi = 1; + int i32_lo = 1; + ulong u64 = 1; + sbyte i08 = 1; + short i16 = -1; - object v1 = (((long)i32_hi) << 32) | (long)i32_lo; + object v1 = (((long)i32_hi) << 32) | (long)i32_lo; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithOrCompilerCase2() - { - // there is a sign extension warning both before and after. so this is not worse to remove the cast. - await VerifyCS.VerifyCodeFixAsync( - """ - public class sign - { - public static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithOrCompilerCase2() + { + // there is a sign extension warning both before and after. so this is not worse to remove the cast. + await VerifyCS.VerifyCodeFixAsync( + """ + public class sign { - int i32_hi = 1; - int i32_lo = 1; - ulong u64 = 1; - sbyte i08 = 1; - short i16 = -1; + public static void Main() + { + int i32_hi = 1; + int i32_lo = 1; + ulong u64 = 1; + sbyte i08 = 1; + short i16 = -1; - object v2 = (ulong)i32_hi | [|(ulong)|]u64; + object v2 = (ulong)i32_hi | [|(ulong)|]u64; + } } - } - """, - """ - public class sign - { - public static void Main() + """, + """ + public class sign { - int i32_hi = 1; - int i32_lo = 1; - ulong u64 = 1; - sbyte i08 = 1; - short i16 = -1; + public static void Main() + { + int i32_hi = 1; + int i32_lo = 1; + ulong u64 = 1; + sbyte i08 = 1; + short i16 = -1; - object v2 = (ulong)i32_hi | u64; + object v2 = (ulong)i32_hi | u64; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithOrCompilerCase3() - { - var source = - """ - public class sign - { - public static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithOrCompilerCase3() + { + var source = + """ + public class sign { - int i32_hi = 1; - int i32_lo = 1; - ulong u64 = 1; - sbyte i08 = 1; - short i16 = -1; + public static void Main() + { + int i32_hi = 1; + int i32_lo = 1; + ulong u64 = 1; + sbyte i08 = 1; + short i16 = -1; - object v3 = (ulong)i32_hi | (ulong)i32_lo; + object v3 = (ulong)i32_hi | (ulong)i32_lo; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithOrCompilerCase4() - { - // there is a sign extension warning both before and after. so this is not worse to remove the cast. - await VerifyCS.VerifyCodeFixAsync( - """ - public class sign - { - public static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithOrCompilerCase4() + { + // there is a sign extension warning both before and after. so this is not worse to remove the cast. + await VerifyCS.VerifyCodeFixAsync( + """ + public class sign { - int i32_hi = 1; - int i32_lo = 1; - ulong u64 = 1; - sbyte i08 = 1; - short i16 = -1; + public static void Main() + { + int i32_hi = 1; + int i32_lo = 1; + ulong u64 = 1; + sbyte i08 = 1; + short i16 = -1; - object v4 = [|(ulong)|](uint)(ushort)i08 | (ulong)i32_lo; + object v4 = [|(ulong)|](uint)(ushort)i08 | (ulong)i32_lo; + } } - } - """, - """ - public class sign - { - public static void Main() + """, + """ + public class sign { - int i32_hi = 1; - int i32_lo = 1; - ulong u64 = 1; - sbyte i08 = 1; - short i16 = -1; + public static void Main() + { + int i32_hi = 1; + int i32_lo = 1; + ulong u64 = 1; + sbyte i08 = 1; + short i16 = -1; - object v4 = (ushort)i08 | (ulong)i32_lo; + object v4 = (ushort)i08 | (ulong)i32_lo; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithOrCompilerCase5() - { + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithOrCompilerCase5() + { - await VerifyCS.VerifyCodeFixAsync(""" - public class sign - { - public static void Main() + await VerifyCS.VerifyCodeFixAsync(""" + public class sign { - int i32_hi = 1; - int i32_lo = 1; - ulong u64 = 1; - sbyte i08 = 1; - short i16 = -1; + public static void Main() + { + int i32_hi = 1; + int i32_lo = 1; + ulong u64 = 1; + sbyte i08 = 1; + short i16 = -1; - object v5 = (int)i08 | [|(int)|]i32_lo; + object v5 = (int)i08 | [|(int)|]i32_lo; + } } - } - """, - """ - public class sign - { - public static void Main() + """, + """ + public class sign { - int i32_hi = 1; - int i32_lo = 1; - ulong u64 = 1; - sbyte i08 = 1; - short i16 = -1; + public static void Main() + { + int i32_hi = 1; + int i32_lo = 1; + ulong u64 = 1; + sbyte i08 = 1; + short i16 = -1; - object v5 = (int)i08 | i32_lo; + object v5 = (int)i08 | i32_lo; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithOrCompilerCase6() - { - var source = - """ - public class sign - { - public static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithOrCompilerCase6() + { + var source = + """ + public class sign { - int i32_hi = 1; - int i32_lo = 1; - ulong u64 = 1; - sbyte i08 = 1; - short i16 = -1; + public static void Main() + { + int i32_hi = 1; + int i32_lo = 1; + ulong u64 = 1; + sbyte i08 = 1; + short i16 = -1; - object v6 = (((ulong)i32_hi) << 32) | (uint) i32_lo; + object v6 = (((ulong)i32_hi) << 32) | (uint) i32_lo; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithOrCompilerCase7() - { - var source = - """ - public class sign - { - public static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithOrCompilerCase7() + { + var source = + """ + public class sign { - int i32_hi = 1; - int i32_lo = 1; - ulong u64 = 1; - sbyte i08 = 1; - short i16 = -1; + public static void Main() + { + int i32_hi = 1; + int i32_lo = 1; + ulong u64 = 1; + sbyte i08 = 1; + short i16 = -1; - object v7 = 0x0000BEEFU | (uint)i16; + object v7 = 0x0000BEEFU | (uint)i16; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithOrCompilerCase8() - { - var source = - """ - public class sign - { - public static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithOrCompilerCase8() + { + var source = + """ + public class sign { - int i32_hi = 1; - int i32_lo = 1; - ulong u64 = 1; - sbyte i08 = 1; - short i16 = -1; + public static void Main() + { + int i32_hi = 1; + int i32_lo = 1; + ulong u64 = 1; + sbyte i08 = 1; + short i16 = -1; - object v8 = 0xFFFFBEEFU | (uint)i16; + object v8 = 0xFFFFBEEFU | (uint)i16; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithOrCompilerCase9() - { - var source = - """ - public class sign - { - public static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithOrCompilerCase9() + { + var source = + """ + public class sign { - int i32_hi = 1; - int i32_lo = 1; - ulong u64 = 1; - sbyte i08 = 1; - short i16 = -1; + public static void Main() + { + int i32_hi = 1; + int i32_lo = 1; + ulong u64 = 1; + sbyte i08 = 1; + short i16 = -1; - object v9 = 0xDEADBEEFU | (uint)i16; + object v9 = 0xDEADBEEFU | (uint)i16; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithOrCompilerCaseNullable1() - { - var source = - """ - public class sign - { - public static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithOrCompilerCaseNullable1() + { + var source = + """ + public class sign { - int? i32_hi = 1; - int? i32_lo = 1; - ulong? u64 = 1; - sbyte? i08 = 1; - short? i16 = -1; + public static void Main() + { + int? i32_hi = 1; + int? i32_lo = 1; + ulong? u64 = 1; + sbyte? i08 = 1; + short? i16 = -1; - object v1 = (((long?)i32_hi) << 32) | (long?)i32_lo; + object v1 = (((long?)i32_hi) << 32) | (long?)i32_lo; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithOrCompilerCaseNullable2() - { - // there is a sign extension warning both before and after. so this is not worse to remove the cast. - await VerifyCS.VerifyCodeFixAsync(""" - public class sign - { - public static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithOrCompilerCaseNullable2() + { + // there is a sign extension warning both before and after. so this is not worse to remove the cast. + await VerifyCS.VerifyCodeFixAsync(""" + public class sign { - int? i32_hi = 1; - int? i32_lo = 1; - ulong? u64 = 1; - sbyte? i08 = 1; - short? i16 = -1; + public static void Main() + { + int? i32_hi = 1; + int? i32_lo = 1; + ulong? u64 = 1; + sbyte? i08 = 1; + short? i16 = -1; - object v2 = (ulong?)i32_hi | [|(ulong?)|]u64; + object v2 = (ulong?)i32_hi | [|(ulong?)|]u64; + } } - } - """, """ - public class sign - { - public static void Main() + """, """ + public class sign { - int? i32_hi = 1; - int? i32_lo = 1; - ulong? u64 = 1; - sbyte? i08 = 1; - short? i16 = -1; + public static void Main() + { + int? i32_hi = 1; + int? i32_lo = 1; + ulong? u64 = 1; + sbyte? i08 = 1; + short? i16 = -1; - object v2 = (ulong?)i32_hi | u64; + object v2 = (ulong?)i32_hi | u64; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithOrCompilerCaseNullable3() - { - var source = - """ - public class sign - { - public static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithOrCompilerCaseNullable3() + { + var source = + """ + public class sign { - int? i32_hi = 1; - int? i32_lo = 1; - ulong? u64 = 1; - sbyte? i08 = 1; - short? i16 = -1; + public static void Main() + { + int? i32_hi = 1; + int? i32_lo = 1; + ulong? u64 = 1; + sbyte? i08 = 1; + short? i16 = -1; - object v3 = (ulong?)i32_hi | (ulong?)i32_lo; + object v3 = (ulong?)i32_hi | (ulong?)i32_lo; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithOrCompilerCaseNullable4() - { - // there is a sign extension warning both before and after. so this is not worse to remove the cast. - await VerifyCS.VerifyCodeFixAsync(""" - public class sign - { - public static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithOrCompilerCaseNullable4() + { + // there is a sign extension warning both before and after. so this is not worse to remove the cast. + await VerifyCS.VerifyCodeFixAsync(""" + public class sign { - int? i32_hi = 1; - int? i32_lo = 1; - ulong? u64 = 1; - sbyte? i08 = 1; - short? i16 = -1; + public static void Main() + { + int? i32_hi = 1; + int? i32_lo = 1; + ulong? u64 = 1; + sbyte? i08 = 1; + short? i16 = -1; - object v4 = [|(ulong?)|][|(uint?)|](ushort?)i08 | (ulong?)i32_lo; + object v4 = [|(ulong?)|][|(uint?)|](ushort?)i08 | (ulong?)i32_lo; + } } - } - """, """ - public class sign - { - public static void Main() + """, """ + public class sign { - int? i32_hi = 1; - int? i32_lo = 1; - ulong? u64 = 1; - sbyte? i08 = 1; - short? i16 = -1; + public static void Main() + { + int? i32_hi = 1; + int? i32_lo = 1; + ulong? u64 = 1; + sbyte? i08 = 1; + short? i16 = -1; - object v4 = (ushort?)i08 | (ulong?)i32_lo; + object v4 = (ushort?)i08 | (ulong?)i32_lo; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithOrCompilerCaseNullable5() - { + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithOrCompilerCaseNullable5() + { - await VerifyCS.VerifyCodeFixAsync(""" - public class sign - { - public static void Main() + await VerifyCS.VerifyCodeFixAsync(""" + public class sign { - int? i32_hi = 1; - int? i32_lo = 1; - ulong? u64 = 1; - sbyte? i08 = 1; - short? i16 = -1; + public static void Main() + { + int? i32_hi = 1; + int? i32_lo = 1; + ulong? u64 = 1; + sbyte? i08 = 1; + short? i16 = -1; - object v5 = (int?)i08 | [|(int?)|]i32_lo; + object v5 = (int?)i08 | [|(int?)|]i32_lo; + } } - } - """, - """ - public class sign - { - public static void Main() + """, + """ + public class sign { - int? i32_hi = 1; - int? i32_lo = 1; - ulong? u64 = 1; - sbyte? i08 = 1; - short? i16 = -1; + public static void Main() + { + int? i32_hi = 1; + int? i32_lo = 1; + ulong? u64 = 1; + sbyte? i08 = 1; + short? i16 = -1; - object v5 = (int?)i08 | i32_lo; + object v5 = (int?)i08 | i32_lo; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithOrCompilerCaseNullable6() - { - var source = - """ - public class sign - { - public static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithOrCompilerCaseNullable6() + { + var source = + """ + public class sign { - int? i32_hi = 1; - int? i32_lo = 1; - ulong? u64 = 1; - sbyte? i08 = 1; - short? i16 = -1; + public static void Main() + { + int? i32_hi = 1; + int? i32_lo = 1; + ulong? u64 = 1; + sbyte? i08 = 1; + short? i16 = -1; - object v6 = (((ulong?)i32_hi) << 32) | (uint?)i32_lo; + object v6 = (((ulong?)i32_hi) << 32) | (uint?)i32_lo; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithOrCompilerCaseNullable7() - { - var source = - """ - public class sign - { - public static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithOrCompilerCaseNullable7() + { + var source = + """ + public class sign { - int? i32_hi = 1; - int? i32_lo = 1; - ulong? u64 = 1; - sbyte? i08 = 1; - short? i16 = -1; + public static void Main() + { + int? i32_hi = 1; + int? i32_lo = 1; + ulong? u64 = 1; + sbyte? i08 = 1; + short? i16 = -1; - object v7 = 0x0000BEEFU | (uint?)i16; + object v7 = 0x0000BEEFU | (uint?)i16; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithOrCompilerCaseNullable8() - { - var source = - """ - public class sign - { - public static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithOrCompilerCaseNullable8() + { + var source = + """ + public class sign { - int? i32_hi = 1; - int? i32_lo = 1; - ulong? u64 = 1; - sbyte? i08 = 1; - short? i16 = -1; + public static void Main() + { + int? i32_hi = 1; + int? i32_lo = 1; + ulong? u64 = 1; + sbyte? i08 = 1; + short? i16 = -1; - object v8 = 0xFFFFBEEFU | (uint?)i16; + object v8 = 0xFFFFBEEFU | (uint?)i16; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] - public async Task TestSignExtensionWithOrCompilerCaseNullable9() - { - var source = - """ - public class sign - { - public static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40414")] + public async Task TestSignExtensionWithOrCompilerCaseNullable9() + { + var source = + """ + public class sign { - int? i32_hi = 1; - int? i32_lo = 1; - ulong? u64 = 1; - sbyte? i08 = 1; - short? i16 = -1; + public static void Main() + { + int? i32_hi = 1; + int? i32_lo = 1; + ulong? u64 = 1; + sbyte? i08 = 1; + short? i16 = -1; - object v9 = 0xDEADBEEFU | (uint?)i16; + object v9 = 0xDEADBEEFU | (uint?)i16; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20211")] - public async Task DoNotRemoveNullCastInSwitch1() - { - var source = - """ - class Program - { - static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20211")] + public async Task DoNotRemoveNullCastInSwitch1() + { + var source = + """ + class Program { - switch ((object)null) + static void Main() { - case bool _: - break; + switch ((object)null) + { + case bool _: + break; + } } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20211")] - public async Task DoNotRemoveNullCastInSwitch2() - { - var source = - """ - class Program - { - static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20211")] + public async Task DoNotRemoveNullCastInSwitch2() + { + var source = + """ + class Program { - switch ((object)(null)) + static void Main() { - case bool _: - break; + switch ((object)(null)) + { + case bool _: + break; + } } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20211")] - public async Task DoNotRemoveNullCastInSwitch3() - { - var source = - """ - class Program - { - static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20211")] + public async Task DoNotRemoveNullCastInSwitch3() + { + var source = + """ + class Program { - switch ((bool?)null) + static void Main() { - case bool _: - break; + switch ((bool?)null) + { + case bool _: + break; + } } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20211")] - public async Task DoNotRemoveNullCastInSwitch4() - { - var source = - """ - class Program - { - static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20211")] + public async Task DoNotRemoveNullCastInSwitch4() + { + var source = + """ + class Program { - switch ((bool?)(null)) + static void Main() { - case bool _: - break; + switch ((bool?)(null)) + { + case bool _: + break; + } } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20211")] - public async Task DoNotRemoveNullCastInSwitch5() - { - var source = - """ - class Program - { - static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20211")] + public async Task DoNotRemoveNullCastInSwitch5() + { + var source = + """ + class Program { - switch (((object)null)) + static void Main() { - case bool _: - break; + switch (((object)null)) + { + case bool _: + break; + } } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20211")] - public async Task DoNotRemoveDefaultCastInSwitch1() - { - var source = - """ - class Program - { - static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20211")] + public async Task DoNotRemoveDefaultCastInSwitch1() + { + var source = + """ + class Program { - switch ((object)default) + static void Main() { - case bool _: - break; + switch ((object)default) + { + case bool _: + break; + } } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20211")] - public async Task DoNotRemoveDefaultCastInSwitch2() - { - var source = - """ - class Program - { - static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20211")] + public async Task DoNotRemoveDefaultCastInSwitch2() + { + var source = + """ + class Program { - switch ((object)(default)) + static void Main() { - case bool _: - break; + switch ((object)(default)) + { + case bool _: + break; + } } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20211")] - public async Task DoNotRemoveDefaultCastInSwitch3() - { - var source = - """ - class Program - { - static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20211")] + public async Task DoNotRemoveDefaultCastInSwitch3() + { + var source = + """ + class Program { - switch ((bool?)default) + static void Main() { - case bool _: - break; + switch ((bool?)default) + { + case bool _: + break; + } } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20211")] - public async Task DoNotRemoveDefaultCastInSwitch4() - { - var source = - """ - class Program - { - static void Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20211")] + public async Task DoNotRemoveDefaultCastInSwitch4() + { + var source = + """ + class Program { - switch ((bool?)(default)) + static void Main() { - case bool _: - break; + switch ((bool?)(default)) + { + case bool _: + break; + } } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20211")] - public async Task DoNotRemoveDoubleNullCastInSwitch1() - { - // Removing the 'object' cast would make `case object:` unreachable. - var source = - """ - class Program - { - static int Main() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20211")] + public async Task DoNotRemoveDoubleNullCastInSwitch1() + { + // Removing the 'object' cast would make `case object:` unreachable. + var source = + """ + class Program { - switch ((object)(string)null) + static int Main() { - case null: - return 0; - case string: - return 1; - case object: - return 2; + switch ((object)(string)null) + { + case null: + return 0; + case string: + return 1; + case object: + return 2; + } } } - } - """; - - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp9, - }.RunAsync(); - } + """; - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task DoNotRemoveNecessaryCastInConditional1() - { - var source = - """ - class C + await new VerifyCS.Test { - void M(bool x) + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp9, + }.RunAsync(); + } + + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task DoNotRemoveNecessaryCastInConditional1() + { + var source = + """ + class C { - int? y = x ? (int?)1 : default; + void M(bool x) + { + int? y = x ? (int?)1 : default; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task DoNotRemoveNecessaryCastInConditional2() - { - var source = - """ - class C - { - void M(bool x) + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task DoNotRemoveNecessaryCastInConditional2() + { + var source = + """ + class C { - int? y = x ? ((int?)1) : default; + void M(bool x) + { + int? y = x ? ((int?)1) : default; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task DoNotRemoveNecessaryCastInConditional3() - { - var source = - """ - class C - { - void M(bool x) + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task DoNotRemoveNecessaryCastInConditional3() + { + var source = + """ + class C { - int? y = x ? (int?)1 : (default); + void M(bool x) + { + int? y = x ? (int?)1 : (default); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task DoNotRemoveNecessaryCastInConditional4_CSharp8() - { - var source = - """ - class C - { - void M(bool x) + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task DoNotRemoveNecessaryCastInConditional4_CSharp8() + { + var source = + """ + class C { - int? y = x ? (int?)1 : null; + void M(bool x) + { + int? y = x ? (int?)1 : null; + } } - } - """; + """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp8 - }.RunAsync(); - } + await new VerifyCS.Test + { + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp8 + }.RunAsync(); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task DoRemoveUnnecessaryCastInConditional4() - { - await new VerifyCS.Test + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task DoRemoveUnnecessaryCastInConditional4() { - TestCode = """ - class C + await new VerifyCS.Test { - void M(bool x) + TestCode = """ + class C { - int? y = x ? [|(int?)|]1 : null; + void M(bool x) + { + int? y = x ? [|(int?)|]1 : null; + } } - } - """, - FixedCode = """ - class C - { - void M(bool x) + """, + FixedCode = """ + class C { - int? y = x ? 1 : null; + void M(bool x) + { + int? y = x ? 1 : null; + } } - } - """, - LanguageVersion = LanguageVersion.CSharp9, - }.RunAsync(); - } + """, + LanguageVersion = LanguageVersion.CSharp9, + }.RunAsync(); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task DoNotRemoveNecessaryCastInConditional5_CSharp8() - { - var source = - """ - class C - { - void M(bool x) + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task DoNotRemoveNecessaryCastInConditional5_CSharp8() + { + var source = + """ + class C { - int? y = x ? ((int?)1) : null; + void M(bool x) + { + int? y = x ? ((int?)1) : null; + } } - } - """; + """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp8 - }.RunAsync(); - } + await new VerifyCS.Test + { + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp8 + }.RunAsync(); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task DoRemoveUnnecessaryCastInConditional5() - { - await new VerifyCS.Test + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task DoRemoveUnnecessaryCastInConditional5() { - TestCode = """ - class C + await new VerifyCS.Test { - void M(bool x) + TestCode = """ + class C { - int? y = x ? ([|(int?)|]1) : null; + void M(bool x) + { + int? y = x ? ([|(int?)|]1) : null; + } } - } - """, - FixedCode = """ - class C - { - void M(bool x) + """, + FixedCode = """ + class C { - int? y = x ? 1 : null; + void M(bool x) + { + int? y = x ? 1 : null; + } } - } - """, - LanguageVersion = LanguageVersion.CSharp9, - }.RunAsync(); - } + """, + LanguageVersion = LanguageVersion.CSharp9, + }.RunAsync(); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task DoNotRemoveNecessaryCastInConditional6_CSharp8() - { - var source = - """ - class C - { - void M(bool x) + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task DoNotRemoveNecessaryCastInConditional6_CSharp8() + { + var source = + """ + class C { - int? y = x ? (int?)1 : (null); + void M(bool x) + { + int? y = x ? (int?)1 : (null); + } } - } - """; + """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp8, - }.RunAsync(); - } + await new VerifyCS.Test + { + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp8, + }.RunAsync(); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task DoRemoveUnnecessaryCastInConditional6_CSharp8() - { - await new VerifyCS.Test + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task DoRemoveUnnecessaryCastInConditional6_CSharp8() { - TestCode = """ - class C + await new VerifyCS.Test { - void M(bool x) + TestCode = """ + class C { - int? y = x ? [|(int?)|]1 : (null); - } - } - """, - FixedCode = """ - class C - { - void M(bool x) + void M(bool x) + { + int? y = x ? [|(int?)|]1 : (null); + } + } + """, + FixedCode = """ + class C { - int? y = x ? 1 : (null); + void M(bool x) + { + int? y = x ? 1 : (null); + } } - } - """, - LanguageVersion = LanguageVersion.CSharp9, - }.RunAsync(); - } + """, + LanguageVersion = LanguageVersion.CSharp9, + }.RunAsync(); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task DoNotRemoveNecessaryCastInConditional7() - { - var source = - """ - class C - { - void M(bool x) + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task DoNotRemoveNecessaryCastInConditional7() + { + var source = + """ + class C { - int? y = x ? default : (int?)1; + void M(bool x) + { + int? y = x ? default : (int?)1; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task DoNotRemoveNecessaryCastInConditional8() - { - var source = - """ - class C - { - void M(bool x) + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task DoNotRemoveNecessaryCastInConditional8() + { + var source = + """ + class C { - int? y = x ? default : ((int?)1); + void M(bool x) + { + int? y = x ? default : ((int?)1); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task DoNotRemoveNecessaryCastInConditional9() - { - var source = - """ - class C - { - void M(bool x) + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task DoNotRemoveNecessaryCastInConditional9() + { + var source = + """ + class C { - int? y = x ? (default) : (int?)1; + void M(bool x) + { + int? y = x ? (default) : (int?)1; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task DoNotRemoveNecessaryCastInConditional10_CSharp8() - { - var source = - """ - class C - { - void M(bool x) + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task DoNotRemoveNecessaryCastInConditional10_CSharp8() + { + var source = + """ + class C { - int? y = x ? null : (int?)1; + void M(bool x) + { + int? y = x ? null : (int?)1; + } } - } - """; + """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp8 - }.RunAsync(); - } + await new VerifyCS.Test + { + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp8 + }.RunAsync(); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task DoRemoveUnnecessaryCastInConditional10() - { - await new VerifyCS.Test + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task DoRemoveUnnecessaryCastInConditional10() { - TestCode = """ - class C + await new VerifyCS.Test { - void M(bool x) + TestCode = """ + class C { - int? y = x ? null : [|(int?)|]1; + void M(bool x) + { + int? y = x ? null : [|(int?)|]1; + } } - } - """, - FixedCode = """ - class C - { - void M(bool x) + """, + FixedCode = """ + class C { - int? y = x ? null : 1; + void M(bool x) + { + int? y = x ? null : 1; + } } - } - """, - LanguageVersion = LanguageVersion.CSharp9, - }.RunAsync(); - } + """, + LanguageVersion = LanguageVersion.CSharp9, + }.RunAsync(); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task DoNotRemoveNecessaryCastInConditional11_CSharp() - { - var source = - """ - class C - { - void M(bool x) + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task DoNotRemoveNecessaryCastInConditional11_CSharp() + { + var source = + """ + class C { - int? y = x ? null : ((int?)1); + void M(bool x) + { + int? y = x ? null : ((int?)1); + } } - } - """; + """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp8 - }.RunAsync(); - } + await new VerifyCS.Test + { + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp8 + }.RunAsync(); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task DoRemoveUnnecessaryCastInConditional11() - { - await new VerifyCS.Test + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task DoRemoveUnnecessaryCastInConditional11() { - TestCode = """ - class C + await new VerifyCS.Test { - void M(bool x) + TestCode = """ + class C { - int? y = x ? null : ([|(int?)|]1); + void M(bool x) + { + int? y = x ? null : ([|(int?)|]1); + } } - } - """, - FixedCode = """ - class C - { - void M(bool x) + """, + FixedCode = """ + class C { - int? y = x ? null : 1; + void M(bool x) + { + int? y = x ? null : 1; + } } - } - """, - LanguageVersion = LanguageVersion.CSharp9, - }.RunAsync(); - } + """, + LanguageVersion = LanguageVersion.CSharp9, + }.RunAsync(); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task DoNotRemoveNecessaryCastInConditional12_CSharp8() - { - var source = - """ - class C - { - void M(bool x) + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task DoNotRemoveNecessaryCastInConditional12_CSharp8() + { + var source = + """ + class C { - int? y = x ? (null) : (int?)1; + void M(bool x) + { + int? y = x ? (null) : (int?)1; + } } - } - """; + """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp8 - }.RunAsync(); - } + await new VerifyCS.Test + { + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp8 + }.RunAsync(); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task DoRemoveUnnecessaryCastInConditional12() - { - await new VerifyCS.Test + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task DoRemoveUnnecessaryCastInConditional12() { - TestCode = """ - class C + await new VerifyCS.Test { - void M(bool x) + TestCode = """ + class C { - int? y = x ? (null) : [|(int?)|]1; + void M(bool x) + { + int? y = x ? (null) : [|(int?)|]1; + } } - } - """, - FixedCode = """ - class C - { - void M(bool x) + """, + FixedCode = """ + class C { - int? y = x ? (null) : 1; + void M(bool x) + { + int? y = x ? (null) : 1; + } } - } - """, - LanguageVersion = LanguageVersion.CSharp9, - }.RunAsync(); - } + """, + LanguageVersion = LanguageVersion.CSharp9, + }.RunAsync(); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task DoNotRemoveNecessaryCastInConditional13() - { - var source = - """ - class C - { - void M(bool x, int? z) + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task DoNotRemoveNecessaryCastInConditional13() + { + var source = + """ + class C { - var y = x ? (long?)z : null; + void M(bool x, int? z) + { + var y = x ? (long?)z : null; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task DoNotRemoveNecessaryCastInConditional14() - { - var source = - """ - class C - { - void M(bool x, int? z) + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task DoNotRemoveNecessaryCastInConditional14() + { + var source = + """ + class C { - var y = x ? (long?)z : default; + void M(bool x, int? z) + { + var y = x ? (long?)z : default; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task RemoveUnecessaryCastInConditional1() - { - var source = - """ - class C - { - void M(bool x) + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task RemoveUnecessaryCastInConditional1() + { + var source = + """ + class C { - int? y = x ? [|(int)|]1 : default; + void M(bool x) + { + int? y = x ? [|(int)|]1 : default; + } } - } - """; + """; - var fixedCode = - """ - class C - { - void M(bool x) + var fixedCode = + """ + class C { - int? y = x ? 1 : default; + void M(bool x) + { + int? y = x ? 1 : default; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, fixedCode); - } + await VerifyCS.VerifyCodeFixAsync(source, fixedCode); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task RemoveUnecessaryCastInConditional2() - { - var source = - """ - class C - { - void M(bool x) + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task RemoveUnecessaryCastInConditional2() + { + var source = + """ + class C { - int? y = x ? [|(int)|]1 : 0; + void M(bool x) + { + int? y = x ? [|(int)|]1 : 0; + } } - } - """; + """; - var fixedCode = - """ - class C - { - void M(bool x) + var fixedCode = + """ + class C { - int? y = x ? 1 : 0; + void M(bool x) + { + int? y = x ? 1 : 0; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, fixedCode); - } + await VerifyCS.VerifyCodeFixAsync(source, fixedCode); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task RemoveUnecessaryCastInConditional3() - { - var source = - """ - class C - { - void M(bool x, int? z) + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task RemoveUnecessaryCastInConditional3() + { + var source = + """ + class C { - int? y = x ? [|(int)|]1 : z; + void M(bool x, int? z) + { + int? y = x ? [|(int)|]1 : z; + } } - } - """; + """; - var fixedCode = - """ - class C - { - void M(bool x, int? z) + var fixedCode = + """ + class C { - int? y = x ? 1 : z; + void M(bool x, int? z) + { + int? y = x ? 1 : z; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, fixedCode); - } + await VerifyCS.VerifyCodeFixAsync(source, fixedCode); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task RemoveUnecessaryCastInConditional4() - { - var source = - """ - class C - { - void M(bool x, int? z) + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task RemoveUnecessaryCastInConditional4() + { + var source = + """ + class C { - int? y = x ? [|(int?)|]1 : z; + void M(bool x, int? z) + { + int? y = x ? [|(int?)|]1 : z; + } } - } - """; + """; - var fixedCode = - """ - class C - { - void M(bool x, int? z) + var fixedCode = + """ + class C { - int? y = x ? 1 : z; + void M(bool x, int? z) + { + int? y = x ? 1 : z; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, fixedCode); - } + await VerifyCS.VerifyCodeFixAsync(source, fixedCode); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task RemoveUnecessaryCastInConditional5() - { - var source = - """ - class C - { - void M(bool x) + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task RemoveUnecessaryCastInConditional5() + { + var source = + """ + class C { - int? y = x ? [|(int?)|]1 : 0; + void M(bool x) + { + int? y = x ? [|(int?)|]1 : 0; + } } - } - """; - var fixedCode = - """ - class C - { - void M(bool x) + """; + var fixedCode = + """ + class C { - int? y = x ? 1 : 0; + void M(bool x) + { + int? y = x ? 1 : 0; + } } - } - """; - - await new VerifyCS.Test - { - TestCode = source, - FixedCode = fixedCode, - LanguageVersion = LanguageVersion.CSharp9, - }.RunAsync(); - } + """; - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task RemoveUnnecessaryCastInConditional6() - { - var source = - """ - class C + await new VerifyCS.Test { - void M(bool x, int? z) + TestCode = source, + FixedCode = fixedCode, + LanguageVersion = LanguageVersion.CSharp9, + }.RunAsync(); + } + + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task RemoveUnnecessaryCastInConditional6() + { + var source = + """ + class C { - int? y = x ? [|(int?)|]z : null; + void M(bool x, int? z) + { + int? y = x ? [|(int?)|]z : null; + } } - } - """; - var fixedCode = - """ - class C - { - void M(bool x, int? z) + """; + var fixedCode = + """ + class C { - int? y = x ? z : null; + void M(bool x, int? z) + { + int? y = x ? z : null; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, fixedCode); - } + await VerifyCS.VerifyCodeFixAsync(source, fixedCode); + } - [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] - public async Task RemoveUnnecessaryCastInConditional7() - { - var source = - """ - class C - { - void M(bool x, int? z) + [Fact, WorkItem(20211, "https://github.com/dotnet/roslyn/issues/21613")] + public async Task RemoveUnnecessaryCastInConditional7() + { + var source = + """ + class C { - int? y = x ? [|(int?)|]z : default; + void M(bool x, int? z) + { + int? y = x ? [|(int?)|]z : default; + } } - } - """; - var fixedCode = - """ - class C - { - void M(bool x, int? z) + """; + var fixedCode = + """ + class C { - int? y = x ? z : default; + void M(bool x, int? z) + { + int? y = x ? z : default; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, fixedCode); - } + await VerifyCS.VerifyCodeFixAsync(source, fixedCode); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20742")] - public async Task DoNotRemoveNamedArgToParamsParameter1() - { - var source = - """ - class Program - { - public void M() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20742")] + public async Task DoNotRemoveNamedArgToParamsParameter1() + { + var source = + """ + class Program { - object[] takesArgs = null; - TakesParams(bar: (object)takesArgs, goo: true); - } + public void M() + { + object[] takesArgs = null; + TakesParams(bar: (object)takesArgs, goo: true); + } - private void TakesParams(bool goo, params object[] bar) - { + private void TakesParams(bool goo, params object[] bar) + { + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20742")] - public async Task DoRemoveNamedArgToParamsParameter1() - { - var source = - """ - class Program - { - public void M() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20742")] + public async Task DoRemoveNamedArgToParamsParameter1() + { + var source = + """ + class Program { - object[] takesArgs = null; - TakesParams(bar: [|(object[])|]takesArgs, goo: true); - } + public void M() + { + object[] takesArgs = null; + TakesParams(bar: [|(object[])|]takesArgs, goo: true); + } - private void TakesParams(bool goo, params object[] bar) - { + private void TakesParams(bool goo, params object[] bar) + { + } } - } - """; - var fixedCode = - """ - class Program - { - public void M() + """; + var fixedCode = + """ + class Program { - object[] takesArgs = null; - TakesParams(bar: takesArgs, goo: true); - } + public void M() + { + object[] takesArgs = null; + TakesParams(bar: takesArgs, goo: true); + } - private void TakesParams(bool goo, params object[] bar) - { + private void TakesParams(bool goo, params object[] bar) + { + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, fixedCode); - } + await VerifyCS.VerifyCodeFixAsync(source, fixedCode); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20742")] - public async Task DoRemoveNamedArgToParamsParameter2() - { - var source = - """ - class Program - { - public void M() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20742")] + public async Task DoRemoveNamedArgToParamsParameter2() + { + var source = + """ + class Program { - string[] takesArgs = null; - TakesParams(bar: [|(object[])|]takesArgs, goo: true); - } + public void M() + { + string[] takesArgs = null; + TakesParams(bar: [|(object[])|]takesArgs, goo: true); + } - private void TakesParams(bool goo, params object[] bar) - { + private void TakesParams(bool goo, params object[] bar) + { + } } - } - """; - var fixedCode = - """ - class Program - { - public void M() + """; + var fixedCode = + """ + class Program { - string[] takesArgs = null; - TakesParams(bar: takesArgs, goo: true); - } + public void M() + { + string[] takesArgs = null; + TakesParams(bar: takesArgs, goo: true); + } - private void TakesParams(bool goo, params object[] bar) - { + private void TakesParams(bool goo, params object[] bar) + { + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, fixedCode); - } + await VerifyCS.VerifyCodeFixAsync(source, fixedCode); + } - [Fact] - public async Task ObjectCastInInterpolation1() - { - var source = - """ - class Program - { - public void M(int x, int z) + [Fact] + public async Task ObjectCastInInterpolation1() + { + var source = + """ + class Program { - var v = $"x {[|(object)|]1} z"; + public void M(int x, int z) + { + var v = $"x {[|(object)|]1} z"; + } } - } - """; - var fixedCode = - """ - class Program - { - public void M(int x, int z) + """; + var fixedCode = + """ + class Program { - var v = $"x {1} z"; + public void M(int x, int z) + { + var v = $"x {1} z"; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, fixedCode); - } + await VerifyCS.VerifyCodeFixAsync(source, fixedCode); + } - [Fact] - public async Task ObjectCastInInterpolation2() - { - var source = - """ - class Program - { - public void M(int x, int z) + [Fact] + public async Task ObjectCastInInterpolation2() + { + var source = + """ + class Program { - var v = $"x {([|(object)|]1)} z"; + public void M(int x, int z) + { + var v = $"x {([|(object)|]1)} z"; + } } - } - """; - var fixedCode = - """ - class Program - { - public void M(int x, int z) + """; + var fixedCode = + """ + class Program { - var v = $"x {1} z"; + public void M(int x, int z) + { + var v = $"x {1} z"; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, fixedCode); - } + await VerifyCS.VerifyCodeFixAsync(source, fixedCode); + } - [Fact] - public async Task TestIdentityDoubleCast() - { - var source = - """ - class Program - { - public void M(object x) + [Fact] + public async Task TestIdentityDoubleCast() + { + var source = + """ + class Program { - var v = [|(int)|](int)x; + public void M(object x) + { + var v = [|(int)|](int)x; + } } - } - """; - var fixedCode = - """ - class Program - { - public void M(object x) + """; + var fixedCode = + """ + class Program { - var v = (int)x; + public void M(object x) + { + var v = (int)x; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, fixedCode); - } + await VerifyCS.VerifyCodeFixAsync(source, fixedCode); + } - [Fact] - public async Task TestUnintendedReferenceComparison1() - { - var source = """ - using System; + [Fact] + public async Task TestUnintendedReferenceComparison1() + { + var source = """ + using System; - public class Symbol - { - public static bool operator ==(Symbol a, Symbol b) => false; - public static bool operator !=(Symbol a, Symbol b) => false; - } + public class Symbol + { + public static bool operator ==(Symbol a, Symbol b) => false; + public static bool operator !=(Symbol a, Symbol b) => false; + } - public class MethodSymbol : Symbol - { - } + public class MethodSymbol : Symbol + { + } - class Program - { - void Main() + class Program { - Object a1 = null; - MethodSymbol a2 = new MethodSymbol(); + void Main() + { + Object a1 = null; + MethodSymbol a2 = new MethodSymbol(); - Console.WriteLine(a1 == (object)a2); + Console.WriteLine(a1 == (object)a2); + } } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact] - public async Task TestUnintendedReferenceComparison2() - { - var source = """ - using System; + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - public class Symbol - { - public static bool operator ==(Symbol a, Symbol b) => false; - public static bool operator !=(Symbol a, Symbol b) => false; - } + [Fact] + public async Task TestUnintendedReferenceComparison2() + { + var source = """ + using System; - public class MethodSymbol : Symbol - { - } - - class Program - { - void Main() + public class Symbol { - Object a1 = null; - MethodSymbol a2 = new MethodSymbol(); + public static bool operator ==(Symbol a, Symbol b) => false; + public static bool operator !=(Symbol a, Symbol b) => false; + } - Console.WriteLine((object)a1 == a2); + public class MethodSymbol : Symbol + { } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } - [Fact] - public async Task TestUnintendedReferenceComparison3() - { - var source = """ - using System; + class Program + { + void Main() + { + Object a1 = null; + MethodSymbol a2 = new MethodSymbol(); - public class Symbol - { - public static bool operator ==(Symbol a, Symbol b) => false; - public static bool operator !=(Symbol a, Symbol b) => false; - } + Console.WriteLine((object)a1 == a2); + } + } + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - public class MethodSymbol : Symbol - { - } + [Fact] + public async Task TestUnintendedReferenceComparison3() + { + var source = """ + using System; - class Program - { - void Main() + public class Symbol { - Object a1 = null; - MethodSymbol a2 = new MethodSymbol(); + public static bool operator ==(Symbol a, Symbol b) => false; + public static bool operator !=(Symbol a, Symbol b) => false; + } - Console.WriteLine(a1 != (object)a2); + public class MethodSymbol : Symbol + { } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } - [Fact] - public async Task TestUnintendedReferenceComparison4() - { - var source = """ - using System; + class Program + { + void Main() + { + Object a1 = null; + MethodSymbol a2 = new MethodSymbol(); - public class Symbol - { - public static bool operator ==(Symbol a, Symbol b) => false; - public static bool operator !=(Symbol a, Symbol b) => false; - } + Console.WriteLine(a1 != (object)a2); + } + } + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - public class MethodSymbol : Symbol - { - } + [Fact] + public async Task TestUnintendedReferenceComparison4() + { + var source = """ + using System; - class Program - { - void Main() + public class Symbol { - Object a1 = null; - MethodSymbol a2 = new MethodSymbol(); + public static bool operator ==(Symbol a, Symbol b) => false; + public static bool operator !=(Symbol a, Symbol b) => false; + } - Console.WriteLine(a1 != a2); + public class MethodSymbol : Symbol + { } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + class Program + { + void Main() + { + Object a1 = null; + MethodSymbol a2 = new MethodSymbol(); - [Fact] - public async Task TestUnintendedReferenceComparison5() - { - var source = """ - using System; + Console.WriteLine(a1 != a2); + } + } + """; - public class Symbol - { - public static bool operator ==(Symbol a, Symbol b) => false; - public static bool operator !=(Symbol a, Symbol b) => false; - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - public class MethodSymbol : Symbol - { - } + [Fact] + public async Task TestUnintendedReferenceComparison5() + { + var source = """ + using System; - class Program - { - void Main() + public class Symbol { - Object a1 = null; - MethodSymbol a2 = new MethodSymbol(); + public static bool operator ==(Symbol a, Symbol b) => false; + public static bool operator !=(Symbol a, Symbol b) => false; + } - Console.WriteLine(a2 == a1); + public class MethodSymbol : Symbol + { } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + class Program + { + void Main() + { + Object a1 = null; + MethodSymbol a2 = new MethodSymbol(); - [Fact] - public async Task TestUnintendedReferenceComparison6() - { - var source = """ - using System; + Console.WriteLine(a2 == a1); + } + } + """; - public class Symbol - { - public static bool operator ==(Symbol a, Symbol b) => false; - public static bool operator !=(Symbol a, Symbol b) => false; - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - public class MethodSymbol : Symbol - { - } + [Fact] + public async Task TestUnintendedReferenceComparison6() + { + var source = """ + using System; - class Program - { - void Main() + public class Symbol { - Object a1 = null; - MethodSymbol a2 = new MethodSymbol(); + public static bool operator ==(Symbol a, Symbol b) => false; + public static bool operator !=(Symbol a, Symbol b) => false; + } - Console.WriteLine((object)a2 == a1); + public class MethodSymbol : Symbol + { } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } - [Fact] - public async Task TestUnintendedReferenceComparison7() - { - var source = """ - using System; + class Program + { + void Main() + { + Object a1 = null; + MethodSymbol a2 = new MethodSymbol(); - public class Symbol - { - public static bool operator ==(Symbol a, Symbol b) => false; - public static bool operator !=(Symbol a, Symbol b) => false; - } + Console.WriteLine((object)a2 == a1); + } + } + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - public class MethodSymbol : Symbol - { - } + [Fact] + public async Task TestUnintendedReferenceComparison7() + { + var source = """ + using System; - class Program - { - void Main() + public class Symbol { - Object a1 = null; - MethodSymbol a2 = new MethodSymbol(); + public static bool operator ==(Symbol a, Symbol b) => false; + public static bool operator !=(Symbol a, Symbol b) => false; + } - Console.WriteLine(a2 != (object)a1); + public class MethodSymbol : Symbol + { } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } - [Fact] - public async Task TestUnintendedReferenceComparison8() - { - var source = """ - using System; + class Program + { + void Main() + { + Object a1 = null; + MethodSymbol a2 = new MethodSymbol(); - public class Symbol - { - public static bool operator ==(Symbol a, Symbol b) => false; - public static bool operator !=(Symbol a, Symbol b) => false; - } + Console.WriteLine(a2 != (object)a1); + } + } + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - public class MethodSymbol : Symbol - { - } + [Fact] + public async Task TestUnintendedReferenceComparison8() + { + var source = """ + using System; - class Program - { - void Main() + public class Symbol { - Object a1 = null; - MethodSymbol a2 = new MethodSymbol(); + public static bool operator ==(Symbol a, Symbol b) => false; + public static bool operator !=(Symbol a, Symbol b) => false; + } - Console.WriteLine((object)a2 != a1); + public class MethodSymbol : Symbol + { } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } - [Fact] - public async Task TestIntendedReferenceComparison1() - { - var source = - """ - using System; + class Program + { + void Main() + { + Object a1 = null; + MethodSymbol a2 = new MethodSymbol(); - public class Symbol - { - public static bool operator ==(Symbol a, Symbol b) => false; - public static bool operator !=(Symbol a, Symbol b) => false; - } + Console.WriteLine((object)a2 != a1); + } + } + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - public class MethodSymbol : Symbol - { - } + [Fact] + public async Task TestIntendedReferenceComparison1() + { + var source = + """ + using System; - class Program - { - void Main() + public class Symbol { - MethodSymbol a1 = null; - MethodSymbol a2 = new MethodSymbol(); + public static bool operator ==(Symbol a, Symbol b) => false; + public static bool operator !=(Symbol a, Symbol b) => false; + } - Console.WriteLine(a1 == (object)a2); + public class MethodSymbol : Symbol + { } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + class Program + { + void Main() + { + MethodSymbol a1 = null; + MethodSymbol a2 = new MethodSymbol(); - [Fact] - public async Task TestIntendedReferenceComparison2() - { - var source = - """ - using System; + Console.WriteLine(a1 == (object)a2); + } + } + """; - public class Symbol - { - public static bool operator ==(Symbol a, Symbol b) => false; - public static bool operator !=(Symbol a, Symbol b) => false; - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - public class MethodSymbol : Symbol - { - } + [Fact] + public async Task TestIntendedReferenceComparison2() + { + var source = + """ + using System; - class Program - { - void Main() + public class Symbol { - MethodSymbol a1 = null; - MethodSymbol a2 = new MethodSymbol(); + public static bool operator ==(Symbol a, Symbol b) => false; + public static bool operator !=(Symbol a, Symbol b) => false; + } - Console.WriteLine((object)a1 == a2); + public class MethodSymbol : Symbol + { } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + class Program + { + void Main() + { + MethodSymbol a1 = null; + MethodSymbol a2 = new MethodSymbol(); - [Fact] - public async Task TestIntendedReferenceComparison3() - { - var source = - """ - using System; + Console.WriteLine((object)a1 == a2); + } + } + """; - public class Symbol - { - public static bool operator ==(Symbol a, Symbol b) => false; - public static bool operator !=(Symbol a, Symbol b) => false; - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - public class MethodSymbol : Symbol - { - } + [Fact] + public async Task TestIntendedReferenceComparison3() + { + var source = + """ + using System; - class Program - { - void Main() + public class Symbol { - MethodSymbol a1 = null; - MethodSymbol a2 = new MethodSymbol(); + public static bool operator ==(Symbol a, Symbol b) => false; + public static bool operator !=(Symbol a, Symbol b) => false; + } - Console.WriteLine(a1 != (object)a2); + public class MethodSymbol : Symbol + { } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + class Program + { + void Main() + { + MethodSymbol a1 = null; + MethodSymbol a2 = new MethodSymbol(); - [Fact] - public async Task TestIntendedReferenceComparison4() - { - var source = - """ - using System; + Console.WriteLine(a1 != (object)a2); + } + } + """; - public class Symbol - { - public static bool operator ==(Symbol a, Symbol b) => false; - public static bool operator !=(Symbol a, Symbol b) => false; - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - public class MethodSymbol : Symbol - { - } + [Fact] + public async Task TestIntendedReferenceComparison4() + { + var source = + """ + using System; - class Program - { - void Main() + public class Symbol { - MethodSymbol a1 = null; - MethodSymbol a2 = new MethodSymbol(); + public static bool operator ==(Symbol a, Symbol b) => false; + public static bool operator !=(Symbol a, Symbol b) => false; + } - Console.WriteLine((object)a1 != a2); + public class MethodSymbol : Symbol + { } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + class Program + { + void Main() + { + MethodSymbol a1 = null; + MethodSymbol a2 = new MethodSymbol(); - [Fact] - public async Task TestIntendedReferenceComparison5() - { - var source = - """ - using System; + Console.WriteLine((object)a1 != a2); + } + } + """; - public class Symbol - { - public static bool operator ==(Symbol a, Symbol b) => false; - public static bool operator !=(Symbol a, Symbol b) => false; - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - public class MethodSymbol : Symbol - { - } + [Fact] + public async Task TestIntendedReferenceComparison5() + { + var source = + """ + using System; - class Program - { - void Main() + public class Symbol { - MethodSymbol a1 = null; - MethodSymbol a2 = new MethodSymbol(); + public static bool operator ==(Symbol a, Symbol b) => false; + public static bool operator !=(Symbol a, Symbol b) => false; + } - Console.WriteLine(a2 == (object)a1); + public class MethodSymbol : Symbol + { } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + class Program + { + void Main() + { + MethodSymbol a1 = null; + MethodSymbol a2 = new MethodSymbol(); - [Fact] - public async Task TestIntendedReferenceComparison6() - { - var source = - """ - using System; + Console.WriteLine(a2 == (object)a1); + } + } + """; - public class Symbol - { - public static bool operator ==(Symbol a, Symbol b) => false; - public static bool operator !=(Symbol a, Symbol b) => false; - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - public class MethodSymbol : Symbol - { - } + [Fact] + public async Task TestIntendedReferenceComparison6() + { + var source = + """ + using System; - class Program - { - void Main() + public class Symbol { - MethodSymbol a1 = null; - MethodSymbol a2 = new MethodSymbol(); + public static bool operator ==(Symbol a, Symbol b) => false; + public static bool operator !=(Symbol a, Symbol b) => false; + } - Console.WriteLine((object)a2 == a1); + public class MethodSymbol : Symbol + { } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + class Program + { + void Main() + { + MethodSymbol a1 = null; + MethodSymbol a2 = new MethodSymbol(); - [Fact] - public async Task TestIntendedReferenceComparison7() - { - var source = - """ - using System; + Console.WriteLine((object)a2 == a1); + } + } + """; - public class Symbol - { - public static bool operator ==(Symbol a, Symbol b) => false; - public static bool operator !=(Symbol a, Symbol b) => false; - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - public class MethodSymbol : Symbol - { - } + [Fact] + public async Task TestIntendedReferenceComparison7() + { + var source = + """ + using System; - class Program - { - void Main() + public class Symbol { - MethodSymbol a1 = null; - MethodSymbol a2 = new MethodSymbol(); + public static bool operator ==(Symbol a, Symbol b) => false; + public static bool operator !=(Symbol a, Symbol b) => false; + } - Console.WriteLine(a2 != (object)a1); + public class MethodSymbol : Symbol + { } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + class Program + { + void Main() + { + MethodSymbol a1 = null; + MethodSymbol a2 = new MethodSymbol(); - [Fact] - public async Task TestIntendedReferenceComparison8() - { - var source = - """ - using System; + Console.WriteLine(a2 != (object)a1); + } + } + """; - public class Symbol - { - public static bool operator ==(Symbol a, Symbol b) => false; - public static bool operator !=(Symbol a, Symbol b) => false; - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - public class MethodSymbol : Symbol - { - } + [Fact] + public async Task TestIntendedReferenceComparison8() + { + var source = + """ + using System; - class Program - { - void Main() + public class Symbol { - MethodSymbol a1 = null; - MethodSymbol a2 = new MethodSymbol(); + public static bool operator ==(Symbol a, Symbol b) => false; + public static bool operator !=(Symbol a, Symbol b) => false; + } - Console.WriteLine((object)a2 != a1); + public class MethodSymbol : Symbol + { } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + class Program + { + void Main() + { + MethodSymbol a1 = null; + MethodSymbol a2 = new MethodSymbol(); - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/44382")] - public async Task DoNotRemoveCastOnParameterInitializer1() - { - var source = - """ - enum E : byte { } - class C { void F() { void f(E e = (E)byte.MaxValue) { } } } - """; + Console.WriteLine((object)a2 != a1); + } + } + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/44382")] - public async Task DoNotRemoveCastOnParameterInitializer2() - { - var source = - """ - enum E : byte { } - class C { void f(E e = (E)byte.MaxValue) { } } - """; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/44382")] + public async Task DoNotRemoveCastOnParameterInitializer1() + { + var source = + """ + enum E : byte { } + class C { void F() { void f(E e = (E)byte.MaxValue) { } } } + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/45695")] - public async Task DoNotRemoveNonObjectCastInsideInterpolation() - { - var source = - """ - class Other - { - void Goo() - { - char c = '4'; - string s = $"{(int)c:X4}"; - } - } - """; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/44382")] + public async Task DoNotRemoveCastOnParameterInitializer2() + { + var source = + """ + enum E : byte { } + class C { void f(E e = (E)byte.MaxValue) { } } + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/45695")] - public async Task DoRemoveObjectCastInsideInterpolation() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class Other - { - void Goo() - { - char c = '4'; - string s = $"{[|(object)|]c:X4}"; - } - } - """, - """ - class Other - { - void Goo() - { - char c = '4'; - string s = $"{c:X4}"; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/45695")] + public async Task DoNotRemoveNonObjectCastInsideInterpolation() + { + var source = + """ + class Other + { + void Goo() + { + char c = '4'; + string s = $"{(int)c:X4}"; + } } - } - """); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47800")] - public async Task RemoveNativeIntCastsAsIdentity() - { - var source = - """ - using System; - - public class C { - public nint N(IntPtr x) => [|(nint)|]x; - } - """; - var fixedCode = - """ - using System; - - public class C { - public nint N(IntPtr x) => x; - } - """; - - var test = new VerifyCS.Test() - { - TestCode = source, - FixedCode = fixedCode, - LanguageVersion = LanguageVersion.CSharp9 - }; - - await test.RunAsync(); - } + """; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47800")] - public async Task DoRemoveNativeIntCasts() - { - var source = - """ - using System; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - public class C { - public nuint N(IntPtr x) => (nuint)(nint)x; - } - """; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/45695")] + public async Task DoRemoveObjectCastInsideInterpolation() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class Other + { + void Goo() + { + char c = '4'; + string s = $"{[|(object)|]c:X4}"; + } + } + """, + """ + class Other + { + void Goo() + { + char c = '4'; + string s = $"{c:X4}"; + } + } + """); + } - var test = new VerifyCS.Test() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47800")] + public async Task RemoveNativeIntCastsAsIdentity() { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp9 - }; + var source = + """ + using System; - await test.RunAsync(); - } + public class C { + public nint N(IntPtr x) => [|(nint)|]x; + } + """; + var fixedCode = + """ + using System; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47800")] - public async Task RemoveNativeUIntCastsAsIdentity() - { - var source = - """ - using System; - - public class C { - public nuint N(UIntPtr x) => [|(nuint)|]x; - } - """; - var fixedCode = - """ - using System; - - public class C { - public nuint N(UIntPtr x) => x; - } - """; - - var test = new VerifyCS.Test() - { - TestCode = source, - FixedCode = fixedCode, - LanguageVersion = LanguageVersion.CSharp9 - }; - - await test.RunAsync(); - } + public class C { + public nint N(IntPtr x) => x; + } + """; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/51123")] - public async Task DoRemoveNativeIntCastsToInt() - { - var source = - """ - using System; + var test = new VerifyCS.Test() + { + TestCode = source, + FixedCode = fixedCode, + LanguageVersion = LanguageVersion.CSharp9 + }; - public class C { - public int N(IntPtr x) => (int)(nint)x; - } - """; + await test.RunAsync(); + } - var test = new VerifyCS.Test() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47800")] + public async Task DoRemoveNativeIntCasts() { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp9 - }; + var source = + """ + using System; - await test.RunAsync(); - } + public class C { + public nuint N(IntPtr x) => (nuint)(nint)x; + } + """; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47800")] - public async Task DoRemoveNativeUIntCasts() - { - var source = - """ - using System; + var test = new VerifyCS.Test() + { + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp9 + }; - public class C { - public nint N(UIntPtr x) => (nint)(nuint)x; - } - """; + await test.RunAsync(); + } - var test = new VerifyCS.Test() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47800")] + public async Task RemoveNativeUIntCastsAsIdentity() { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp9 - }; - - await test.RunAsync(); - } + var source = + """ + using System; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47800")] - public async Task RemoveIntPtrCastsAsIdentity() - { - var source = - """ - using System; + public class C { + public nuint N(UIntPtr x) => [|(nuint)|]x; + } + """; + var fixedCode = + """ + using System; - class C - { - public void M(IntPtr x) - { - var v = [|(IntPtr)|]x; + public class C { + public nuint N(UIntPtr x) => x; } - } - """; - var fixedCode = - """ - using System; + """; - class C + var test = new VerifyCS.Test() { - public void M(IntPtr x) - { - var v = x; - } - } - """; + TestCode = source, + FixedCode = fixedCode, + LanguageVersion = LanguageVersion.CSharp9 + }; - await VerifyCS.VerifyCodeFixAsync(source, fixedCode); - } + await test.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47800")] - public async Task RemoveUIntPtrCastsAsIdentity() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/51123")] + public async Task DoRemoveNativeIntCastsToInt() + { + var source = + """ + using System; - class C - { - public void M(UIntPtr x) - { - var v = [|(UIntPtr)|]x; + public class C { + public int N(IntPtr x) => (int)(nint)x; } - } - """; - var fixedCode = - """ - using System; + """; - class C + var test = new VerifyCS.Test() { - public void M(UIntPtr x) - { - var v = x; - } - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, fixedCode); - } + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp9 + }; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49140")] - public async Task DoNotRemoveBitwiseNotOfUnsignedExtendedValue1() - { - var source = - """ - class C - { - public static ulong P(ulong a, uint b) - { - return a & ~(ulong)b; - } - } - """; + await test.RunAsync(); + } - var test = new VerifyCS.Test() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47800")] + public async Task DoRemoveNativeUIntCasts() { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp9 - }; + var source = + """ + using System; - await test.RunAsync(); - } + public class C { + public nint N(UIntPtr x) => (nint)(nuint)x; + } + """; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49140")] - public async Task DoNotRemoveBitwiseNotOfUnsignedExtendedValue2() - { - var source = - """ - class C + var test = new VerifyCS.Test() { - public static nuint N(nuint a, uint b) - { - return a & ~(nuint)b; - } - } - """; + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp9 + }; - var test = new VerifyCS.Test() - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp9 - }; + await test.RunAsync(); + } - await test.RunAsync(); - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47800")] + public async Task RemoveIntPtrCastsAsIdentity() + { + var source = + """ + using System; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49140")] - public async Task DoNotRemoveBitwiseNotOfUnsignedExtendedValue3() - { - var source = - """ - class C - { - public static ulong N() + class C { - return ~(ulong)uint.MaxValue; + public void M(IntPtr x) + { + var v = [|(IntPtr)|]x; + } } - } - """; + """; + var fixedCode = + """ + using System; - var test = new VerifyCS.Test() - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp9 - }; + class C + { + public void M(IntPtr x) + { + var v = x; + } + } + """; - await test.RunAsync(); - } + await VerifyCS.VerifyCodeFixAsync(source, fixedCode); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49140")] - public async Task DoRemoveBitwiseNotOfSignExtendedValue1() - { - var test = new VerifyCS.Test() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/47800")] + public async Task RemoveUIntPtrCastsAsIdentity() { - TestCode = """ - class C - { - public static long P(long a, int b) + var source = + """ + using System; + + class C { - return a & ~[|(long)|]b; + public void M(UIntPtr x) + { + var v = [|(UIntPtr)|]x; + } } - } - """, - FixedCode = """ - class C - { - public static long P(long a, int b) + """; + var fixedCode = + """ + using System; + + class C { - return a & ~b; + public void M(UIntPtr x) + { + var v = x; + } } - } - """, - LanguageVersion = LanguageVersion.CSharp9 - }; - - await test.RunAsync(); - } + """; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49140")] - public async Task DoRemoveBitwiseNotOfSignExtendedValue2() - { + await VerifyCS.VerifyCodeFixAsync(source, fixedCode); + } - var test = new VerifyCS.Test() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49140")] + public async Task DoNotRemoveBitwiseNotOfUnsignedExtendedValue1() { - TestCode = """ - class C - { - public static nint N(nint a, int b) + var source = + """ + class C { - return a & ~[|(nint)|]b; + public static ulong P(ulong a, uint b) + { + return a & ~(ulong)b; + } } - } - """, - FixedCode = """ - class C + """; + + var test = new VerifyCS.Test() { - public static nint N(nint a, int b) - { - return a & ~b; - } - } - """, - LanguageVersion = LanguageVersion.CSharp9 - }; + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp9 + }; - await test.RunAsync(); - } + await test.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/50000")] - public async Task KeepNecessaryCastIfRemovalWouldCreateIllegalConditionalExpression() - { - await new VerifyCS.Test + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49140")] + public async Task DoNotRemoveBitwiseNotOfUnsignedExtendedValue2() { - TestCode = """ - class C + var source = + """ + class C + { + public static nuint N(nuint a, uint b) + { + return a & ~(nuint)b; + } + } + """; + + var test = new VerifyCS.Test() { - ushort Goo(string s) - => s is null ? (ushort)1234 : ushort.Parse(s); - } - """, - LanguageVersion = LanguageVersion.CSharp9, - }.RunAsync(); - } + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp9 + }; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/50000")] - public async Task RemoveUnnecessaryCastWhenConditionalExpressionIsLegal() - { - await new VerifyCS.Test + await test.RunAsync(); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49140")] + public async Task DoNotRemoveBitwiseNotOfUnsignedExtendedValue3() { - TestCode = """ - class C - { - uint Goo(string s) - => s is null ? [|(uint)|]1234 : uint.Parse(s); - } - """, - FixedCode = """ - class C - { - uint Goo(string s) - => s is null ? 1234 : uint.Parse(s); - } - """, - LanguageVersion = LanguageVersion.CSharp9, - }.RunAsync(); - } + var source = + """ + class C + { + public static ulong N() + { + return ~(ulong)uint.MaxValue; + } + } + """; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/52524")] - public async Task DoNotRemoveForValueTaskConstrutor() - { - var source = - """ - #nullable enable + var test = new VerifyCS.Test() + { + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp9 + }; - using System.Threading.Tasks; + await test.RunAsync(); + } - struct ValueTask + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49140")] + public async Task DoRemoveBitwiseNotOfSignExtendedValue1() + { + var test = new VerifyCS.Test() { - public ValueTask(TResult result) + TestCode = """ + class C { + public static long P(long a, int b) + { + return a & ~[|(long)|]b; + } } - - public ValueTask(Task task) + """, + FixedCode = """ + class C { + public static long P(long a, int b) + { + return a & ~b; + } } - } + """, + LanguageVersion = LanguageVersion.CSharp9 + }; - class A - { - static void Main() - { - ValueTask v = new((object?)null); - } - } - """; + await test.RunAsync(); + } - await new VerifyCS.Test + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49140")] + public async Task DoRemoveBitwiseNotOfSignExtendedValue2() { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp9, - }.RunAsync(); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/53698")] - public async Task DoNotRemoveForConditional() - { - var source = - """ - using System.Collections.Generic; - class E + var test = new VerifyCS.Test() { - private object _o; - - public E First + TestCode = """ + class C { - get + public static nint N(nint a, int b) { - return _o is List es ? es[0] : (E)_o; + return a & ~[|(nint)|]b; } } - } - """; - - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp9, - }.RunAsync(); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/55621")] - public async Task DoNotRemoveForNullWithMultipleMatchingParameterTypes() - { - var source = - """ - #nullable enable - using System; - public class TestClass - { - public TestClass(object? value) { } - public TestClass(Func value) { } + """, + FixedCode = """ + class C + { + public static nint N(nint a, int b) + { + return a & ~b; + } + } + """, + LanguageVersion = LanguageVersion.CSharp9 + }; - public TestClass Create1() => new ((object?)null); - } - """; + await test.RunAsync(); + } - await new VerifyCS.Test + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/50000")] + public async Task KeepNecessaryCastIfRemovalWouldCreateIllegalConditionalExpression() { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp9, - }.RunAsync(); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/56207")] - public async Task DoNotRemoveForNintPointerToVoidPointer() - { - var source = - """ - using System; - public class TestClass + await new VerifyCS.Test { - unsafe void M(nint** ptr) + TestCode = """ + class C { - nint value = (nint)(void*)*ptr; + ushort Goo(string s) + => s is null ? (ushort)1234 : ushort.Parse(s); } - } - """; + """, + LanguageVersion = LanguageVersion.CSharp9, + }.RunAsync(); + } - await new VerifyCS.Test + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/50000")] + public async Task RemoveUnnecessaryCastWhenConditionalExpressionIsLegal() { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp9, - }.RunAsync(); - } - - [Fact] - public async Task RemoveUnnecessaryCastInPattern1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class Program + await new VerifyCS.Test { - void Main(int? n) + TestCode = """ + class C { - var v = n is [|(int)|]0; + uint Goo(string s) + => s is null ? [|(uint)|]1234 : uint.Parse(s); } - } - """, - - """ - class Program - { - void Main(int? n) + """, + FixedCode = """ + class C { - var v = n is 0; + uint Goo(string s) + => s is null ? 1234 : uint.Parse(s); } - } - """); - } + """, + LanguageVersion = LanguageVersion.CSharp9, + }.RunAsync(); + } - [Fact(Skip = "https://github.com/dotnet/roslyn/issues/56938")] - public async Task RemoveUnnecessaryNullableCastInPattern1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class Program - { - void Main(int? n) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/52524")] + public async Task DoNotRemoveForValueTaskConstrutor() + { + var source = + """ + #nullable enable + + using System.Threading.Tasks; + + struct ValueTask { - var v = n is [|(int?)|]0; + public ValueTask(TResult result) + { + } + + public ValueTask(Task task) + { + } } - } - """, - """ - class Program - { - void Main(int? n) + class A { - var v = n is 0; + static void Main() + { + ValueTask v = new((object?)null); + } } - } - """); - } + """; - [Fact] - public async Task DoNotRemoveBoxingEnumCast() - { - var source = """ - using System; - class Program + await new VerifyCS.Test { - static void M() - { - object y = (DayOfWeek)0; - Console.WriteLine(y); - } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp9, + }.RunAsync(); + } - [Fact] - public async Task DoRemoveFPCastFromNonFPTypeToWidenedType1() - { - await VerifyCS.VerifyCodeFixAsync(""" - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/53698")] + public async Task DoNotRemoveForConditional() + { + var source = + """ + using System.Collections.Generic; - class Program - { - static void Main() + class E { - int x = int.MaxValue; - double y = x; - double z = [|(float)|]x; - Console.WriteLine(x); - Console.WriteLine(y); - Console.WriteLine(z); - Console.WriteLine(y == z); + private object _o; + + public E First + { + get + { + return _o is List es ? es[0] : (E)_o; + } + } } - } - """, """ - using System; + """; - class Program + await new VerifyCS.Test { - static void Main() - { - int x = int.MaxValue; - double y = x; - double z = x; - Console.WriteLine(x); - Console.WriteLine(y); - Console.WriteLine(z); - Console.WriteLine(y == z); - } - } - """); - } + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp9, + }.RunAsync(); + } - [Fact] - public async Task DoNotRemoveFPCastToWidenedType2() - { - var source = """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/55621")] + public async Task DoNotRemoveForNullWithMultipleMatchingParameterTypes() + { + var source = + """ + #nullable enable + using System; + public class TestClass + { + public TestClass(object? value) { } + public TestClass(Func value) { } + + public TestClass Create1() => new ((object?)null); + } + """; - class Program + await new VerifyCS.Test { - static void Main() - { - float x = 0; - double y = x; - double z = (float)x; - Console.WriteLine(x); - Console.WriteLine(y); - Console.WriteLine(z); - Console.WriteLine(y == z); - } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp9, + }.RunAsync(); + } - [Fact] - public async Task DoNotRemoveCastIfOverriddenMethodHasDifferentReturnType() - { - var source = - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/56207")] + public async Task DoNotRemoveForNintPointerToVoidPointer() + { + var source = + """ + using System; + public class TestClass + { + unsafe void M(nint** ptr) + { + nint value = (nint)(void*)*ptr; + } + } + """; - abstract class Y + await new VerifyCS.Test { - public abstract object Goo(); - } + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp9, + }.RunAsync(); + } - class X : Y - { - static void Main() + [Fact] + public async Task RemoveUnnecessaryCastInPattern1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class Program { - var v = ((Y)new X()).Goo(); + void Main(int? n) + { + var v = n is [|(int)|]0; + } } + """, - public override string {|CS8830:Goo|}() + """ + class Program { - return null; + void Main(int? n) + { + var v = n is 0; + } } - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact] - public async Task KeepCastToObjectToPreserveDynamicOverload() - { - var source = - """ - using System; + """); + } - class C - { - static void Bar(int x, Action y) { } - static void Bar(dynamic x, Action y) { } - - static void Main() + [Fact(Skip = "https://github.com/dotnet/roslyn/issues/56938")] + public async Task RemoveUnnecessaryNullableCastInPattern1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class Program { - Bar((object)1, Console.WriteLine); + void Main(int? n) + { + var v = n is [|(int?)|]0; + } } - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact] - public async Task KeepIntToLongCastWithIComparable() - { - var source = - """ - using System; + """, - class C - { - static void Main() + """ + class Program { - IComparable result = (long)0; + void Main(int? n) + { + var v = n is 0; + } } - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact] - public async Task KeepCastNeededToPickCorrectOverload() - { - // removing the 'byte' cast will switch the overload called. - var source = - """ - using System; + """); + } - class Program - { - static void Main() + [Fact] + public async Task DoNotRemoveBoxingEnumCast() + { + var source = """ + using System; + class Program { - byte z = 0; - Func p = x => 0; - Goo(p, y => (byte)0, z, z); + static void M() + { + object y = (DayOfWeek)0; + Console.WriteLine(y); + } } + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - static void Goo(Func p, Func q, T r, S s) { Console.WriteLine(1); } - static void Goo(Func p, Func q, int r, int s) { Console.WriteLine(2); } - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact] - public async Task CanRemoveExplicitCastToReferenceTypeWhenPassedToDynamic1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - - class C - { - static void Bar(dynamic x, Action y) { } + [Fact] + public async Task DoRemoveFPCastFromNonFPTypeToWidenedType1() + { + await VerifyCS.VerifyCodeFixAsync(""" + using System; - static void Main() + class Program { - Bar([|(object)|]1, Console.WriteLine); + static void Main() + { + int x = int.MaxValue; + double y = x; + double z = [|(float)|]x; + Console.WriteLine(x); + Console.WriteLine(y); + Console.WriteLine(z); + Console.WriteLine(y == z); + } } - } - """, - """ - using System; - - class C - { - static void Bar(dynamic x, Action y) { } + """, """ + using System; - static void Main() + class Program { - Bar(1, Console.WriteLine); + static void Main() + { + int x = int.MaxValue; + double y = x; + double z = x; + Console.WriteLine(x); + Console.WriteLine(y); + Console.WriteLine(z); + Console.WriteLine(y == z); + } } - } - """); - } - - [Fact] - public async Task CanRemoveExplicitCastToReferenceTypeWhenPassedToDynamic2() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + """); + } - class C - { - static void Bar(dynamic x, Action y) { } + [Fact] + public async Task DoNotRemoveFPCastToWidenedType2() + { + var source = """ + using System; - static void Main() + class Program { - Bar([|(IComparable)|]1, Console.WriteLine); + static void Main() + { + float x = 0; + double y = x; + double z = (float)x; + Console.WriteLine(x); + Console.WriteLine(y); + Console.WriteLine(z); + Console.WriteLine(y == z); + } } - } - """, - """ - using System; + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - class C - { - static void Bar(dynamic x, Action y) { } + [Fact] + public async Task DoNotRemoveCastIfOverriddenMethodHasDifferentReturnType() + { + var source = + """ + using System; - static void Main() + abstract class Y { - Bar(1, Console.WriteLine); + public abstract object Goo(); } - } - """); - } - - [Fact] - public async Task NotOnWidenedNumericStoredInObject1() - { - var source = - """ - using System; - class Program - { - static void Main() + class X : Y { - int expr = 0; - object o1 = (long)expr; + static void Main() + { + var v = ((Y)new X()).Goo(); + } + + public override string {|CS8830:Goo|}() + { + return null; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact] - public async Task NotOnWidenedNumericConstantStoredInObject2() - { - var source = - """ - using System; + [Fact] + public async Task KeepCastToObjectToPreserveDynamicOverload() + { + var source = + """ + using System; - class Program - { - static void Main() + class C { - object o1 = (long)0; + static void Bar(int x, Action y) { } + static void Bar(dynamic x, Action y) { } + + static void Main() + { + Bar((object)1, Console.WriteLine); + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact] - public async Task OnNonWidenedNumericStoredInObject1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - class Program - { - static void Main() - { - long lng = 0; - object o1 = [|(long)|]lng; - } - } - """, - """ - using System; + [Fact] + public async Task KeepIntToLongCastWithIComparable() + { + var source = + """ + using System; - class Program - { - static void Main() + class C { - long lng = 0; - object o1 = lng; + static void Main() + { + IComparable result = (long)0; + } } - } - """); - } + """; - [Fact] - public async Task OnNonWidenedNumericConstantStoredInObject2() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - class Program - { - static void Main() - { - object o1 = [|(long)|]0L; - } - } - """, - """ - using System; + [Fact] + public async Task KeepCastNeededToPickCorrectOverload() + { + // removing the 'byte' cast will switch the overload called. + var source = + """ + using System; - class Program - { - static void Main() + class Program { - object o1 = 0L; - } - } - """); - } - - [Fact] - public async Task DisallowNarrowingNullableNumericAsCast() - { - var source = - """ - using System; + static void Main() + { + byte z = 0; + Func p = x => 0; + Goo(p, y => (byte)0, z, z); + } - class Program - { - static void Main() - { - int? data = 1; - var x = data as byte?; - Console.WriteLine(x); + static void Goo(Func p, Func q, T r, S s) { Console.WriteLine(1); } + static void Goo(Func p, Func q, int r, int s) { Console.WriteLine(2); } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact] - public async Task AllowNonNarrowingNullableNumericAsCast() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact] + public async Task CanRemoveExplicitCastToReferenceTypeWhenPassedToDynamic1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - class Program - { - static void Main() + class C { - byte? data = 1; - var x = data [|as byte?|]; - Console.WriteLine(x); - } - } - """, - """ - using System; + static void Bar(dynamic x, Action y) { } - class Program - { - static void Main() - { - byte? data = 1; - var x = data; - Console.WriteLine(x); + static void Main() + { + Bar([|(object)|]1, Console.WriteLine); + } } - } - """); - } + """, + """ + using System; - [Fact] - public async Task CanNotRemoveStackallocToVarOutsideOfUnsafeRegion() - { - var source = """ - using System; - namespace System - { - public readonly ref struct Span - { - unsafe public Span(void* pointer, int length) { } - } - } - class Program - { - static void Main() + class C { - var x = (Span)stackalloc int[8]; + static void Bar(dynamic x, Action y) { } + + static void Main() + { + Bar(1, Console.WriteLine); + } } - } - """; + """); + } - await VerifyCS.VerifyCodeFixAsync(source, source); - } + [Fact] + public async Task CanRemoveExplicitCastToReferenceTypeWhenPassedToDynamic2() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - [Fact] - public async Task CanRemoveStackallocToSpanOutsideOfUnsafeRegion() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - namespace System - { - public readonly ref struct Span - { - unsafe public Span(void* pointer, int length) { } - } - } - class Program - { - static void Main() - { - Span x = [|(Span)|]stackalloc int[8]; // cast can be removed - } - } - """, - """ - using System; - namespace System - { - public readonly ref struct Span + class C { - unsafe public Span(void* pointer, int length) { } - } - } - class Program - { - static void Main() - { - Span x = stackalloc int[8]; // cast can be removed - } - } - """); - } + static void Bar(dynamic x, Action y) { } - [Fact] - public async Task CanNotRemoveStackallocToVarInsideOfUnsafeRegion1() - { - var source = """ - using System; - namespace System - { - public readonly ref struct Span - { - unsafe public Span(void* pointer, int length) { } + static void Main() + { + Bar([|(IComparable)|]1, Console.WriteLine); + } } - } - class Program - { - static void Main() + """, + """ + using System; + + class C { - unsafe + static void Bar(dynamic x, Action y) { } + + static void Main() { - var x = (Span)stackalloc int[8]; // cast can not be removed + Bar(1, Console.WriteLine); } } - } - """; + """); + } - await VerifyCS.VerifyCodeFixAsync(source, source); - } + [Fact] + public async Task NotOnWidenedNumericStoredInObject1() + { + var source = + """ + using System; - [Fact] - public async Task CanNotRemoveStackallocToVarInsideOfUnsafeRegion2() - { - var source = """ - using System; - namespace System - { - public readonly ref struct Span - { - unsafe public Span(void* pointer, int length) { } - } - } - class Program - { - unsafe static void Main() + class Program { - var x = (Span)stackalloc int[8]; // cast can not be removed + static void Main() + { + int expr = 0; + object o1 = (long)expr; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact] - public async Task CanRemoveStackallocToSpanInsideOfUnsafeRegion1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - namespace System - { - public readonly ref struct Span - { - unsafe public Span(void* pointer, int length) { } - } - } - class Program - { - static void Main() + [Fact] + public async Task NotOnWidenedNumericConstantStoredInObject2() + { + var source = + """ + using System; + + class Program { - unsafe + static void Main() { - Span x = [|(Span)|]stackalloc int[8]; // cast can be removed + object o1 = (long)0; } } - } - """, - """ - using System; - namespace System - { - public readonly ref struct Span - { - unsafe public Span(void* pointer, int length) { } - } - } - class Program - { - static void Main() + """; + + await VerifyCS.VerifyCodeFixAsync(source, source); + } + + [Fact] + public async Task OnNonWidenedNumericStoredInObject1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + + class Program { - unsafe + static void Main() { - Span x = stackalloc int[8]; // cast can be removed + long lng = 0; + object o1 = [|(long)|]lng; } } - } - """); - } + """, + """ + using System; - [Fact] - public async Task CanRemoveStackallocToSpanInsideOfUnsafeRegion2() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - namespace System - { - public readonly ref struct Span - { - unsafe public Span(void* pointer, int length) { } - } - } - class Program - { - unsafe static void Main() - { - Span x = [|(Span)|]stackalloc int[8]; // cast can be removed - } - } - """, - """ - using System; - namespace System - { - public readonly ref struct Span - { - unsafe public Span(void* pointer, int length) { } - } - } - class Program - { - unsafe static void Main() + class Program { - Span x = stackalloc int[8]; // cast can be removed + static void Main() + { + long lng = 0; + object o1 = lng; + } } - } - """); - } + """); + } - [Fact] - public async Task CanRemoveStackallocToVarInsideOfUnsafeRegion1() - { - // possibly incorrect error: https://github.com/dotnet/roslyn/issues/57040 - var source = """ - using System; - namespace System - { - public readonly ref struct Span - { - unsafe public Span(void* pointer, int length) { } - } - } - class Program - { - unsafe static void Main() + [Fact] + public async Task OnNonWidenedNumericConstantStoredInObject2() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + + class Program { - var x = {|CS8346:(int*)stackalloc int[8]|}; // cast can be removed + static void Main() + { + object o1 = [|(long)|]0L; + } } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + """, + """ + using System; - [Fact] - public async Task CanRemoveParenthesizedStackallocToVarInsideOfUnsafeRegion1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - namespace System - { - public readonly ref struct Span + class Program { - unsafe public Span(void* pointer, int length) { } + static void Main() + { + object o1 = 0L; + } } - } - class Program - { - unsafe static void Main() + """); + } + + [Fact] + public async Task DisallowNarrowingNullableNumericAsCast() + { + var source = + """ + using System; + + class Program { - var x = [|(Span)|](stackalloc int[8]); // cast can be removed + static void Main() + { + int? data = 1; + var x = data as byte?; + Console.WriteLine(x); + } } - } - """, - """ - using System; - namespace System - { - public readonly ref struct Span + """; + + await VerifyCS.VerifyCodeFixAsync(source, source); + } + + [Fact] + public async Task AllowNonNarrowingNullableNumericAsCast() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + + class Program { - unsafe public Span(void* pointer, int length) { } + static void Main() + { + byte? data = 1; + var x = data [|as byte?|]; + Console.WriteLine(x); + } } - } - class Program - { - unsafe static void Main() + """, + """ + using System; + + class Program { - var x = (stackalloc int[8]); // cast can be removed + static void Main() + { + byte? data = 1; + var x = data; + Console.WriteLine(x); + } } - } - """); - } + """); + } - [Fact] - public async Task CanRemoveStackallocToPointerInsideOfUnsafeRegion1() - { - // Possibly a compiler bug. Unclear why conversion to `(int*)` not allowed. - // https://github.com/dotnet/roslyn/issues/57040 - var source = """ - using System; - namespace System - { - public readonly ref struct Span + [Fact] + public async Task CanNotRemoveStackallocToVarOutsideOfUnsafeRegion() + { + var source = """ + using System; + namespace System { - unsafe public Span(void* pointer, int length) { } + public readonly ref struct Span + { + unsafe public Span(void* pointer, int length) { } + } } - } - class Program - { - unsafe static void Main() + class Program { - int* x = {|CS8346:(int*)stackalloc int[8]|}; // cast can be removed + static void Main() + { + var x = (Span)stackalloc int[8]; + } } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + """; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57062")] - public async Task DoRemoveIdentityCastInConstantPattern1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - class C - { - void M(object o) + [Fact] + public async Task CanRemoveStackallocToSpanOutsideOfUnsafeRegion() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + namespace System { - if (o is [|(int)|]0) + public readonly ref struct Span { + unsafe public Span(void* pointer, int length) { } } } - } - """, - """ - using System; - - class C - { - void M(object o) + class Program { - if (o is 0) + static void Main() { + Span x = [|(Span)|]stackalloc int[8]; // cast can be removed } } - } - """); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57062")] - public async Task DoRemoveIdentityCastInConstantPattern2() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; - - class C - { - void M(object o) + """, + """ + using System; + namespace System { - if (o is [|(long)|]0L) + public readonly ref struct Span { + unsafe public Span(void* pointer, int length) { } } } - } - """, - """ - using System; - - class C - { - void M(object o) + class Program { - if (o is 0L) + static void Main() { + Span x = stackalloc int[8]; // cast can be removed } } - } - """); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57062")] - public async Task DoNotRemoveNonIdentityCastInConstantPattern1() - { - var source = - """ - using System; + """); + } - class C - { - void M(object o) + [Fact] + public async Task CanNotRemoveStackallocToVarInsideOfUnsafeRegion1() + { + var source = """ + using System; + namespace System { - if (o is (sbyte)0) + public readonly ref struct Span { + unsafe public Span(void* pointer, int length) { } } } - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57062")] - public async Task DoNotRemoveNonIdentityCastInConstantPattern2() - { - var source = - """ - using System; - - class C - { - void M(object o) + class Program { - if (o is (sbyte)0 or (short)0) + static void Main() { + unsafe + { + var x = (Span)stackalloc int[8]; // cast can not be removed + } } } - } - """; + """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp9, - }.RunAsync(); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57062")] - public async Task DoNotRemoveNonIdentityCastInConstantPattern3() - { - await new VerifyCS.Test + [Fact] + public async Task CanNotRemoveStackallocToVarInsideOfUnsafeRegion2() { - TestCode = """ - using System; - - class C - { - void M(object o) + var source = """ + using System; + namespace System { - if (o is (sbyte)1 or (short)1 or [|(int)|]1 or (long)1 or - (byte)1 or (ushort)1 or (uint)1 or (ulong)1 or - 1.0 or 1.0f or 1.0m) + public readonly ref struct Span { + unsafe public Span(void* pointer, int length) { } } } - } - """, - FixedCode = """ - using System; - - class C - { - void M(object o) + class Program { - if (o is (sbyte)1 or (short)1 or 1 or (long)1 or - (byte)1 or (ushort)1 or (uint)1 or (ulong)1 or - 1.0 or 1.0f or 1.0m) + unsafe static void Main() { + var x = (Span)stackalloc int[8]; // cast can not be removed } } - } - """, - LanguageVersion = LanguageVersion.CSharp9, - }.RunAsync(); - } + """; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57062")] - public async Task DoNotRemoveNonIdentityCastInConstantPattern4() - { - var source = - """ - using System; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - class C - { - void M(object o) + [Fact] + public async Task CanRemoveStackallocToSpanInsideOfUnsafeRegion1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + namespace System { - if (o is (long)0) + public readonly ref struct Span { + unsafe public Span(void* pointer, int length) { } } } - } - """; - - await VerifyCS.VerifyCodeFixAsync(source, source); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] - public async Task DoNotRemoveEqualityWarningSilencingCast1() - { - var source = - """ - interface IAssembly - { - } + class Program + { + static void Main() + { + unsafe + { + Span x = [|(Span)|]stackalloc int[8]; // cast can be removed + } + } + } + """, + """ + using System; + namespace System + { + public readonly ref struct Span + { + unsafe public Span(void* pointer, int length) { } + } + } + class Program + { + static void Main() + { + unsafe + { + Span x = stackalloc int[8]; // cast can be removed + } + } + } + """); + } - class Assembly : IAssembly - { - public static bool operator ==(Assembly a1, Assembly a2) => false; - public static bool operator !=(Assembly a1, Assembly a2) => false; + [Fact] + public async Task CanRemoveStackallocToSpanInsideOfUnsafeRegion2() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + namespace System + { + public readonly ref struct Span + { + unsafe public Span(void* pointer, int length) { } + } + } + class Program + { + unsafe static void Main() + { + Span x = [|(Span)|]stackalloc int[8]; // cast can be removed + } + } + """, + """ + using System; + namespace System + { + public readonly ref struct Span + { + unsafe public Span(void* pointer, int length) { } + } + } + class Program + { + unsafe static void Main() + { + Span x = stackalloc int[8]; // cast can be removed + } + } + """); + } - public override bool Equals(object obj) => false; - public override int GetHashCode() => 0; - } + [Fact] + public async Task CanRemoveStackallocToVarInsideOfUnsafeRegion1() + { + // possibly incorrect error: https://github.com/dotnet/roslyn/issues/57040 + var source = """ + using System; + namespace System + { + public readonly ref struct Span + { + unsafe public Span(void* pointer, int length) { } + } + } + class Program + { + unsafe static void Main() + { + var x = {|CS8346:(int*)stackalloc int[8]|}; // cast can be removed + } + } + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - class C - { - bool M(Assembly a1, IAssembly a2) - => (object)a1 == a2; - } - """; + [Fact] + public async Task CanRemoveParenthesizedStackallocToVarInsideOfUnsafeRegion1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; + namespace System + { + public readonly ref struct Span + { + unsafe public Span(void* pointer, int length) { } + } + } + class Program + { + unsafe static void Main() + { + var x = [|(Span)|](stackalloc int[8]); // cast can be removed + } + } + """, + """ + using System; + namespace System + { + public readonly ref struct Span + { + unsafe public Span(void* pointer, int length) { } + } + } + class Program + { + unsafe static void Main() + { + var x = (stackalloc int[8]); // cast can be removed + } + } + """); + } - await VerifyCS.VerifyCodeFixAsync(source, source); - } + [Fact] + public async Task CanRemoveStackallocToPointerInsideOfUnsafeRegion1() + { + // Possibly a compiler bug. Unclear why conversion to `(int*)` not allowed. + // https://github.com/dotnet/roslyn/issues/57040 + var source = """ + using System; + namespace System + { + public readonly ref struct Span + { + unsafe public Span(void* pointer, int length) { } + } + } + class Program + { + unsafe static void Main() + { + int* x = {|CS8346:(int*)stackalloc int[8]|}; // cast can be removed + } + } + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] - public async Task DoNotRemoveEqualityWarningSilencingCast2() - { - var source = - """ - interface IAssembly - { - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57062")] + public async Task DoRemoveIdentityCastInConstantPattern1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - class Assembly : IAssembly - { - public static bool operator ==(Assembly a1, Assembly a2) => false; - public static bool operator !=(Assembly a1, Assembly a2) => false; + class C + { + void M(object o) + { + if (o is [|(int)|]0) + { + } + } + } + """, + """ + using System; - public override bool Equals(object obj) => false; - public override int GetHashCode() => 0; - } + class C + { + void M(object o) + { + if (o is 0) + { + } + } + } + """); + } - class C - { - bool M(Assembly a1, IAssembly a2) - => a1 == (object)a2; - } - """; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57062")] + public async Task DoRemoveIdentityCastInConstantPattern2() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + class C + { + void M(object o) + { + if (o is [|(long)|]0L) + { + } + } + } + """, + """ + using System; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] - public async Task DoNotRemoveEqualityWarningSilencingCast3() - { - var source = - """ - interface IAssembly - { - } + class C + { + void M(object o) + { + if (o is 0L) + { + } + } + } + """); + } - class Assembly : IAssembly - { - public static bool operator ==(Assembly a1, Assembly a2) => false; - public static bool operator !=(Assembly a1, Assembly a2) => false; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57062")] + public async Task DoNotRemoveNonIdentityCastInConstantPattern1() + { + var source = + """ + using System; - public override bool Equals(object obj) => false; - public override int GetHashCode() => 0; - } + class C + { + void M(object o) + { + if (o is (sbyte)0) + { + } + } + } + """; - class C - { - bool M(IAssembly a2, Assembly a1) - => (object)a1 == a2; - } - """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - await VerifyCS.VerifyCodeFixAsync(source, source); - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57062")] + public async Task DoNotRemoveNonIdentityCastInConstantPattern2() + { + var source = + """ + using System; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] - public async Task DoNotRemoveEqualityWarningSilencingCast4() - { - var source = - """ - interface IAssembly + class C + { + void M(object o) + { + if (o is (sbyte)0 or (short)0) + { + } + } + } + """; + + await new VerifyCS.Test { - } + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp9, + }.RunAsync(); + } - class Assembly : IAssembly + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57062")] + public async Task DoNotRemoveNonIdentityCastInConstantPattern3() + { + await new VerifyCS.Test { - public static bool operator ==(Assembly a1, Assembly a2) => false; - public static bool operator !=(Assembly a1, Assembly a2) => false; + TestCode = """ + using System; - public override bool Equals(object obj) => false; - public override int GetHashCode() => 0; - } + class C + { + void M(object o) + { + if (o is (sbyte)1 or (short)1 or [|(int)|]1 or (long)1 or + (byte)1 or (ushort)1 or (uint)1 or (ulong)1 or + 1.0 or 1.0f or 1.0m) + { + } + } + } + """, + FixedCode = """ + using System; - class C - { - bool M(IAssembly a2, Assembly a1) - => a1 == (object)a2; - } - """; + class C + { + void M(object o) + { + if (o is (sbyte)1 or (short)1 or 1 or (long)1 or + (byte)1 or (ushort)1 or (uint)1 or (ulong)1 or + 1.0 or 1.0f or 1.0m) + { + } + } + } + """, + LanguageVersion = LanguageVersion.CSharp9, + }.RunAsync(); + } - await VerifyCS.VerifyCodeFixAsync(source, source); - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57062")] + public async Task DoNotRemoveNonIdentityCastInConstantPattern4() + { + var source = + """ + using System; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] - public async Task DoNotRemoveEqualityWarningSilencingCast5() - { - await VerifyCS.VerifyCodeFixAsync( - """ - interface IAssembly - { - } + class C + { + void M(object o) + { + if (o is (long)0) + { + } + } + } + """; - class Assembly : IAssembly - { - public static bool operator ==(Assembly a1, Assembly a2) => false; - public static bool operator !=(Assembly a1, Assembly a2) => false; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - public override bool Equals(object obj) => false; - public override int GetHashCode() => 0; - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] + public async Task DoNotRemoveEqualityWarningSilencingCast1() + { + var source = + """ + interface IAssembly + { + } - class C - { - bool M(IAssembly a2, Assembly a1) - => [|(object)|]a1 == [|(object)|]a2; - } - """, """ - interface IAssembly - { - } + class Assembly : IAssembly + { + public static bool operator ==(Assembly a1, Assembly a2) => false; + public static bool operator !=(Assembly a1, Assembly a2) => false; - class Assembly : IAssembly - { - public static bool operator ==(Assembly a1, Assembly a2) => false; - public static bool operator !=(Assembly a1, Assembly a2) => false; + public override bool Equals(object obj) => false; + public override int GetHashCode() => 0; + } - public override bool Equals(object obj) => false; - public override int GetHashCode() => 0; - } + class C + { + bool M(Assembly a1, IAssembly a2) + => (object)a1 == a2; + } + """; - class C - { - bool M(IAssembly a2, Assembly a1) - => a1 == [|(object)|]a2; - } - """); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] - public async Task DoNotRemoveEqualityWarningSilencingCast6() - { - var source = - """ - interface IAssembly - { - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] + public async Task DoNotRemoveEqualityWarningSilencingCast2() + { + var source = + """ + interface IAssembly + { + } - class Assembly : IAssembly - { - public static bool operator ==(Assembly a1, Assembly a2) => false; - public static bool operator !=(Assembly a1, Assembly a2) => false; + class Assembly : IAssembly + { + public static bool operator ==(Assembly a1, Assembly a2) => false; + public static bool operator !=(Assembly a1, Assembly a2) => false; - public override bool Equals(object obj) => false; - public override int GetHashCode() => 0; - } + public override bool Equals(object obj) => false; + public override int GetHashCode() => 0; + } - class C - { - bool M(Assembly a1, IAssembly a2) - => a1 as object == a2; - } - """; + class C + { + bool M(Assembly a1, IAssembly a2) + => a1 == (object)a2; + } + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] - public async Task DoNotRemoveEqualityWarningSilencingCast7() - { - var source = - """ - interface IAssembly - { - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] + public async Task DoNotRemoveEqualityWarningSilencingCast3() + { + var source = + """ + interface IAssembly + { + } - class Assembly : IAssembly - { - public static bool operator ==(Assembly a1, Assembly a2) => false; - public static bool operator !=(Assembly a1, Assembly a2) => false; + class Assembly : IAssembly + { + public static bool operator ==(Assembly a1, Assembly a2) => false; + public static bool operator !=(Assembly a1, Assembly a2) => false; - public override bool Equals(object obj) => false; - public override int GetHashCode() => 0; - } + public override bool Equals(object obj) => false; + public override int GetHashCode() => 0; + } - class C - { - bool M(Assembly a1, IAssembly a2) - => a1 == a2 as object; - } - """; + class C + { + bool M(IAssembly a2, Assembly a1) + => (object)a1 == a2; + } + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] - public async Task DoNotRemoveEqualityWarningSilencingCast8() - { - var source = - """ - interface IAssembly - { - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] + public async Task DoNotRemoveEqualityWarningSilencingCast4() + { + var source = + """ + interface IAssembly + { + } - class Assembly : IAssembly - { - public static bool operator ==(Assembly a1, Assembly a2) => false; - public static bool operator !=(Assembly a1, Assembly a2) => false; + class Assembly : IAssembly + { + public static bool operator ==(Assembly a1, Assembly a2) => false; + public static bool operator !=(Assembly a1, Assembly a2) => false; - public override bool Equals(object obj) => false; - public override int GetHashCode() => 0; - } + public override bool Equals(object obj) => false; + public override int GetHashCode() => 0; + } - class C - { - bool M(IAssembly a2, Assembly a1) - => a1 as object == a2; - } - """; + class C + { + bool M(IAssembly a2, Assembly a1) + => a1 == (object)a2; + } + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] - public async Task DoNotRemoveEqualityWarningSilencingCast9() - { - var source = - """ - interface IAssembly - { - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] + public async Task DoNotRemoveEqualityWarningSilencingCast5() + { + await VerifyCS.VerifyCodeFixAsync( + """ + interface IAssembly + { + } - class Assembly : IAssembly - { - public static bool operator ==(Assembly a1, Assembly a2) => false; - public static bool operator !=(Assembly a1, Assembly a2) => false; + class Assembly : IAssembly + { + public static bool operator ==(Assembly a1, Assembly a2) => false; + public static bool operator !=(Assembly a1, Assembly a2) => false; - public override bool Equals(object obj) => false; - public override int GetHashCode() => 0; - } + public override bool Equals(object obj) => false; + public override int GetHashCode() => 0; + } - class C - { - bool M(IAssembly a2, Assembly a1) - => a1 == a2 as object; - } - """; + class C + { + bool M(IAssembly a2, Assembly a1) + => [|(object)|]a1 == [|(object)|]a2; + } + """, """ + interface IAssembly + { + } - await VerifyCS.VerifyCodeFixAsync(source, source); - } + class Assembly : IAssembly + { + public static bool operator ==(Assembly a1, Assembly a2) => false; + public static bool operator !=(Assembly a1, Assembly a2) => false; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] - public async Task DoNotRemoveEqualityWarningSilencingCast10() - { - await VerifyCS.VerifyCodeFixAsync( - """ - interface IAssembly - { - } + public override bool Equals(object obj) => false; + public override int GetHashCode() => 0; + } - class Assembly : IAssembly - { - public static bool operator ==(Assembly a1, Assembly a2) => false; - public static bool operator !=(Assembly a1, Assembly a2) => false; + class C + { + bool M(IAssembly a2, Assembly a1) + => a1 == [|(object)|]a2; + } + """); + } - public override bool Equals(object obj) => false; - public override int GetHashCode() => 0; - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] + public async Task DoNotRemoveEqualityWarningSilencingCast6() + { + var source = + """ + interface IAssembly + { + } - class C - { - bool M(IAssembly a2, Assembly a1) - => a1 [|as object|] == a2 [|as object|]; - } - """, """ - interface IAssembly - { - } + class Assembly : IAssembly + { + public static bool operator ==(Assembly a1, Assembly a2) => false; + public static bool operator !=(Assembly a1, Assembly a2) => false; - class Assembly : IAssembly - { - public static bool operator ==(Assembly a1, Assembly a2) => false; - public static bool operator !=(Assembly a1, Assembly a2) => false; + public override bool Equals(object obj) => false; + public override int GetHashCode() => 0; + } - public override bool Equals(object obj) => false; - public override int GetHashCode() => 0; - } + class C + { + bool M(Assembly a1, IAssembly a2) + => a1 as object == a2; + } + """; - class C - { - bool M(IAssembly a2, Assembly a1) - => a1 == a2 as object; - } - """); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] - public async Task DoNotRemoveObjectCastToCauseReferenceEqualityWhenUserDefinedComparisonExists1() - { - var source = - """ - interface IAssembly - { - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] + public async Task DoNotRemoveEqualityWarningSilencingCast7() + { + var source = + """ + interface IAssembly + { + } - class Assembly : IAssembly - { - public static bool operator ==(Assembly a1, Assembly a2) => false; - public static bool operator !=(Assembly a1, Assembly a2) => false; + class Assembly : IAssembly + { + public static bool operator ==(Assembly a1, Assembly a2) => false; + public static bool operator !=(Assembly a1, Assembly a2) => false; - public override bool Equals(object obj) => false; - public override int GetHashCode() => 0; - } + public override bool Equals(object obj) => false; + public override int GetHashCode() => 0; + } - class C - { - bool M(Assembly a2, Assembly a1) - => (object)a1 == a2; - } - """; + class C + { + bool M(Assembly a1, IAssembly a2) + => a1 == a2 as object; + } + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] - public async Task DoNotRemoveObjectCastToCauseReferenceEqualityWhenUserDefinedComparisonExists2() - { - var source = - """ - interface IAssembly - { - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] + public async Task DoNotRemoveEqualityWarningSilencingCast8() + { + var source = + """ + interface IAssembly + { + } - class Assembly : IAssembly - { - public static bool operator ==(Assembly a1, Assembly a2) => false; - public static bool operator !=(Assembly a1, Assembly a2) => false; + class Assembly : IAssembly + { + public static bool operator ==(Assembly a1, Assembly a2) => false; + public static bool operator !=(Assembly a1, Assembly a2) => false; - public override bool Equals(object obj) => false; - public override int GetHashCode() => 0; - } + public override bool Equals(object obj) => false; + public override int GetHashCode() => 0; + } - class C - { - bool M(Assembly a2, Assembly a1) - => a1 == (object)a2; - } - """; + class C + { + bool M(IAssembly a2, Assembly a1) + => a1 as object == a2; + } + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] - public async Task DoNotRemoveObjectCastToCauseReferenceEqualityWhenUserDefinedComparisonExists3() - { - var source = - """ - interface IAssembly - { - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] + public async Task DoNotRemoveEqualityWarningSilencingCast9() + { + var source = + """ + interface IAssembly + { + } - class Assembly : IAssembly - { - public static bool operator ==(Assembly a1, Assembly a2) => false; - public static bool operator !=(Assembly a1, Assembly a2) => false; + class Assembly : IAssembly + { + public static bool operator ==(Assembly a1, Assembly a2) => false; + public static bool operator !=(Assembly a1, Assembly a2) => false; - public override bool Equals(object obj) => false; - public override int GetHashCode() => 0; - } + public override bool Equals(object obj) => false; + public override int GetHashCode() => 0; + } - class C - { - bool M(Assembly a2, Assembly a1) - => a1 as object == a2; - } - """; + class C + { + bool M(IAssembly a2, Assembly a1) + => a1 == a2 as object; + } + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] - public async Task DoNotRemoveObjectCastToCauseReferenceEqualityWhenUserDefinedComparisonExists4() - { - var source = - """ - interface IAssembly - { - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] + public async Task DoNotRemoveEqualityWarningSilencingCast10() + { + await VerifyCS.VerifyCodeFixAsync( + """ + interface IAssembly + { + } - class Assembly : IAssembly - { - public static bool operator ==(Assembly a1, Assembly a2) => false; - public static bool operator !=(Assembly a1, Assembly a2) => false; + class Assembly : IAssembly + { + public static bool operator ==(Assembly a1, Assembly a2) => false; + public static bool operator !=(Assembly a1, Assembly a2) => false; - public override bool Equals(object obj) => false; - public override int GetHashCode() => 0; - } + public override bool Equals(object obj) => false; + public override int GetHashCode() => 0; + } - class C - { - bool M(Assembly a2, Assembly a1) - => a1 == a2 as object; - } - """; + class C + { + bool M(IAssembly a2, Assembly a1) + => a1 [|as object|] == a2 [|as object|]; + } + """, """ + interface IAssembly + { + } - await VerifyCS.VerifyCodeFixAsync(source, source); - } + class Assembly : IAssembly + { + public static bool operator ==(Assembly a1, Assembly a2) => false; + public static bool operator !=(Assembly a1, Assembly a2) => false; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] - public async Task DoRemoveObjectCastToCauseReferenceEqualityOnInterface1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - interface IAssembly - { - } + public override bool Equals(object obj) => false; + public override int GetHashCode() => 0; + } - class C - { - bool M(IAssembly a2, IAssembly a1) - => [|(object)|]a1 == a2; - } - """, - """ - interface IAssembly - { - } + class C + { + bool M(IAssembly a2, Assembly a1) + => a1 == a2 as object; + } + """); + } - class C - { - bool M(IAssembly a2, IAssembly a1) - => a1 == a2; - } - """); - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] + public async Task DoNotRemoveObjectCastToCauseReferenceEqualityWhenUserDefinedComparisonExists1() + { + var source = + """ + interface IAssembly + { + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] - public async Task DoRemoveObjectCastToCauseReferenceEqualityOnInterface2() - { - await VerifyCS.VerifyCodeFixAsync( - """ - interface IAssembly - { - } + class Assembly : IAssembly + { + public static bool operator ==(Assembly a1, Assembly a2) => false; + public static bool operator !=(Assembly a1, Assembly a2) => false; - class C - { - bool M(IAssembly a2, IAssembly a1) - => a1 == [|(object)|]a2; - } - """, - """ - interface IAssembly - { - } + public override bool Equals(object obj) => false; + public override int GetHashCode() => 0; + } - class C - { - bool M(IAssembly a2, IAssembly a1) - => a1 == a2; - } - """); - } + class C + { + bool M(Assembly a2, Assembly a1) + => (object)a1 == a2; + } + """; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] - public async Task DoRemoveObjectCastToCauseReferenceEqualityOnInterface3() - { - await VerifyCS.VerifyCodeFixAsync( - """ - interface IAssembly - { - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - class C - { - bool M(IAssembly a2, IAssembly a1) - => [|(object)|]a1 == [|(object)|]a2; - } - """, - """ - interface IAssembly - { - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] + public async Task DoNotRemoveObjectCastToCauseReferenceEqualityWhenUserDefinedComparisonExists2() + { + var source = + """ + interface IAssembly + { + } - class C - { - bool M(IAssembly a2, IAssembly a1) - => a1 == a2; - } - """); - } + class Assembly : IAssembly + { + public static bool operator ==(Assembly a1, Assembly a2) => false; + public static bool operator !=(Assembly a1, Assembly a2) => false; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] - public async Task DoRemoveObjectCastToCauseReferenceEqualityOnInterface4() - { - await VerifyCS.VerifyCodeFixAsync( - """ - interface IAssembly - { - } + public override bool Equals(object obj) => false; + public override int GetHashCode() => 0; + } - class C - { - bool M(IAssembly a2, IAssembly a1) - => a1 [|as object|] == a2; - } - """, - """ - interface IAssembly - { - } + class C + { + bool M(Assembly a2, Assembly a1) + => a1 == (object)a2; + } + """; - class C - { - bool M(IAssembly a2, IAssembly a1) - => a1 == a2; - } - """); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] - public async Task DoRemoveObjectCastToCauseReferenceEqualityOnInterface5() - { - await VerifyCS.VerifyCodeFixAsync( - """ - interface IAssembly - { - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] + public async Task DoNotRemoveObjectCastToCauseReferenceEqualityWhenUserDefinedComparisonExists3() + { + var source = + """ + interface IAssembly + { + } - class C - { - bool M(IAssembly a2, IAssembly a1) - => a1 == a2 [|as object|]; - } - """, - """ - interface IAssembly - { - } + class Assembly : IAssembly + { + public static bool operator ==(Assembly a1, Assembly a2) => false; + public static bool operator !=(Assembly a1, Assembly a2) => false; - class C - { - bool M(IAssembly a2, IAssembly a1) - => a1 == a2; - } - """); - } + public override bool Equals(object obj) => false; + public override int GetHashCode() => 0; + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] - public async Task DoRemoveObjectCastToCauseReferenceEqualityOnInterface6() - { - await VerifyCS.VerifyCodeFixAsync( - """ - interface IAssembly - { - } + class C + { + bool M(Assembly a2, Assembly a1) + => a1 as object == a2; + } + """; - class C - { - bool M(IAssembly a2, IAssembly a1) - => a1 [|as object|] == a2 [|as object|]; - } - """, - """ - interface IAssembly - { - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - class C - { - bool M(IAssembly a2, IAssembly a1) - => a1 == a2; - } - """); - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] + public async Task DoNotRemoveObjectCastToCauseReferenceEqualityWhenUserDefinedComparisonExists4() + { + var source = + """ + interface IAssembly + { + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57063")] - public async Task DoNotRemoveNullableIntToNullableEnumCast() - { - var source = - """ - enum E { } + class Assembly : IAssembly + { + public static bool operator ==(Assembly a1, Assembly a2) => false; + public static bool operator !=(Assembly a1, Assembly a2) => false; - class Program - { - static E? Main(object o) + public override bool Equals(object obj) => false; + public override int GetHashCode() => 0; + } + + class C { - return (E?)(int?)o; + bool M(Assembly a2, Assembly a1) + => a1 == a2 as object; } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] - public async Task DoNotRemoveNRTCast1() - { - var source = - """ - #nullable enable + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] + public async Task DoRemoveObjectCastToCauseReferenceEqualityOnInterface1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + interface IAssembly + { + } - using System.Collections.Generic; - using System.Linq; + class C + { + bool M(IAssembly a2, IAssembly a1) + => [|(object)|]a1 == a2; + } + """, + """ + interface IAssembly + { + } - class Node - { - public readonly string Name = ""; - } + class C + { + bool M(IAssembly a2, IAssembly a1) + => a1 == a2; + } + """); + } - class C - { - void M(IList nodes) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] + public async Task DoRemoveObjectCastToCauseReferenceEqualityOnInterface2() + { + await VerifyCS.VerifyCodeFixAsync( + """ + interface IAssembly { - Dictionary map = nodes.ToDictionary(t => t.Name, t => (Node?)t); } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + class C + { + bool M(IAssembly a2, IAssembly a1) + => a1 == [|(object)|]a2; + } + """, + """ + interface IAssembly + { + } - [Fact(Skip = "https://github.com/dotnet/roslyn/issues/56938")] - [WorkItem("https://github.com/dotnet/roslyn/issues/57064")] - public async Task DoRemoveNRTCastInConditional1() - { - await new VerifyCS.Test + class C + { + bool M(IAssembly a2, IAssembly a1) + => a1 == a2; + } + """); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] + public async Task DoRemoveObjectCastToCauseReferenceEqualityOnInterface3() { - TestCode = """ - #nullable enable + await VerifyCS.VerifyCodeFixAsync( + """ + interface IAssembly + { + } - using System.Collections.Generic; - using System.Linq; + class C + { + bool M(IAssembly a2, IAssembly a1) + => [|(object)|]a1 == [|(object)|]a2; + } + """, + """ + interface IAssembly + { + } - class C + class C + { + bool M(IAssembly a2, IAssembly a1) + => a1 == a2; + } + """); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] + public async Task DoRemoveObjectCastToCauseReferenceEqualityOnInterface4() + { + await VerifyCS.VerifyCodeFixAsync( + """ + interface IAssembly + { + } + + class C + { + bool M(IAssembly a2, IAssembly a1) + => a1 [|as object|] == a2; + } + """, + """ + interface IAssembly + { + } + + class C + { + bool M(IAssembly a2, IAssembly a1) + => a1 == a2; + } + """); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] + public async Task DoRemoveObjectCastToCauseReferenceEqualityOnInterface5() + { + await VerifyCS.VerifyCodeFixAsync( + """ + interface IAssembly + { + } + + class C + { + bool M(IAssembly a2, IAssembly a1) + => a1 == a2 [|as object|]; + } + """, + """ + interface IAssembly + { + } + + class C + { + bool M(IAssembly a2, IAssembly a1) + => a1 == a2; + } + """); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57065")] + public async Task DoRemoveObjectCastToCauseReferenceEqualityOnInterface6() + { + await VerifyCS.VerifyCodeFixAsync( + """ + interface IAssembly + { + } + + class C + { + bool M(IAssembly a2, IAssembly a1) + => a1 [|as object|] == a2 [|as object|]; + } + """, + """ + interface IAssembly + { + } + + class C + { + bool M(IAssembly a2, IAssembly a1) + => a1 == a2; + } + """); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57063")] + public async Task DoNotRemoveNullableIntToNullableEnumCast() + { + var source = + """ + enum E { } + + class Program + { + static E? Main(object o) + { + return (E?)(int?)o; + } + } + """; + + await VerifyCS.VerifyCodeFixAsync(source, source); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] + public async Task DoNotRemoveNRTCast1() + { + var source = + """ + #nullable enable + + using System.Collections.Generic; + using System.Linq; + + class Node + { + public readonly string Name = ""; + } + + class C + { + void M(IList nodes) + { + Dictionary map = nodes.ToDictionary(t => t.Name, t => (Node?)t); + } + } + """; + + await VerifyCS.VerifyCodeFixAsync(source, source); + } + + [Fact(Skip = "https://github.com/dotnet/roslyn/issues/56938")] + [WorkItem("https://github.com/dotnet/roslyn/issues/57064")] + public async Task DoRemoveNRTCastInConditional1() + { + await new VerifyCS.Test { - string? M(bool b, string s) + TestCode = """ + #nullable enable + + using System.Collections.Generic; + using System.Linq; + + class C { - return b ? [|(string?)|]s : null; + string? M(bool b, string s) + { + return b ? [|(string?)|]s : null; + } } - } - """, - FixedCode = - """ - #nullable enable + """, + FixedCode = + """ + #nullable enable - using System.Collections.Generic; - using System.Linq; + using System.Collections.Generic; + using System.Linq; - class C - { - string? M(bool b, string s) + class C { - return b ? s : null; + string? M(bool b, string s) + { + return b ? s : null; + } } - } - """, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + """, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] - public async Task DoRemoveNRTCastInConditional2() - { - await VerifyCS.VerifyCodeFixAsync( - """ - #nullable enable + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] + public async Task DoRemoveNRTCastInConditional2() + { + await VerifyCS.VerifyCodeFixAsync( + """ + #nullable enable - using System.Collections.Generic; - using System.Linq; + using System.Collections.Generic; + using System.Linq; - class C - { - string? M(bool b, string s) + class C { - return b ? s : [|(string?)|]null; + string? M(bool b, string s) + { + return b ? s : [|(string?)|]null; + } } - } - """, - """ - #nullable enable + """, + """ + #nullable enable - using System.Collections.Generic; - using System.Linq; + using System.Collections.Generic; + using System.Linq; - class C - { - string? M(bool b, string s) + class C { - return b ? s : null; + string? M(bool b, string s) + { + return b ? s : null; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] - public async Task DoRemoveUnnecessaryWideningConstantCastInConditional1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class C - { - void M(int a) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] + public async Task DoRemoveUnnecessaryWideningConstantCastInConditional1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class C { - long f1 = (a == 5) ? 4 : [|(long)|]5; + void M(int a) + { + long f1 = (a == 5) ? 4 : [|(long)|]5; + } } - } - """, - """ - class C - { - void M(int a) + """, + """ + class C { - long f1 = (a == 5) ? 4 : 5; + void M(int a) + { + long f1 = (a == 5) ? 4 : 5; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] - public async Task DoNotRemoveNnecessaryWideningConstantCastInConditional1() - { - var source = """ - class C - { - void M(int a) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] + public async Task DoNotRemoveNnecessaryWideningConstantCastInConditional1() + { + var source = """ + class C { - var f1 = (a == 5) ? 4 : (long)5; + void M(int a) + { + var f1 = (a == 5) ? 4 : (long)5; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] - public async Task DoRemoveUnnecessaryWideningCastInConditional2() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class C - { - void M(int a, int b, int c) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] + public async Task DoRemoveUnnecessaryWideningCastInConditional2() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class C { - long f1 = (a == 5) ? b : [|(long)|]c; + void M(int a, int b, int c) + { + long f1 = (a == 5) ? b : [|(long)|]c; + } } - } - """, - """ - class C - { - void M(int a, int b, int c) + """, + """ + class C { - long f1 = (a == 5) ? b : c; + void M(int a, int b, int c) + { + long f1 = (a == 5) ? b : c; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] - public async Task DoNotRemoveNecessaryWideningCastInConditional2() - { - var source = """ - class C - { - void M(int a, int b, int c) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] + public async Task DoNotRemoveNecessaryWideningCastInConditional2() + { + var source = """ + class C { - var f1 = (a == 5) ? b : (long)c; + void M(int a, int b, int c) + { + var f1 = (a == 5) ? b : (long)c; + } } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] - public async Task DoRemoveUnnecessaryWideningNullableConstantCastInConditional3() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class C - { - void M(int a, int b, int c) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] + public async Task DoRemoveUnnecessaryWideningNullableConstantCastInConditional3() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class C { - int? f1 = (a == 5) ? [|(int?)|]0 : 1; + void M(int a, int b, int c) + { + int? f1 = (a == 5) ? [|(int?)|]0 : 1; + } } - } - """, - """ - class C - { - void M(int a, int b, int c) + """, + """ + class C { - int? f1 = (a == 5) ? 0 : 1; + void M(int a, int b, int c) + { + int? f1 = (a == 5) ? 0 : 1; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] - public async Task DoNotRemoveNecessaryWideningNullableConstantCastInConditional3() - { - var source = """ - class C - { - void M(int a, int b, int c) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] + public async Task DoNotRemoveNecessaryWideningNullableConstantCastInConditional3() + { + var source = """ + class C { - var f1 = (a == 5) ? (int?)0 : 1; + void M(int a, int b, int c) + { + var f1 = (a == 5) ? (int?)0 : 1; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] - public async Task DoRemoveUnnecessaryWideningNullableCastInConditional3() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class C - { - void M(int a, int b, int c) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] + public async Task DoRemoveUnnecessaryWideningNullableCastInConditional3() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class C { - int? f1 = (a == 5) ? [|(int?)|]b : c; + void M(int a, int b, int c) + { + int? f1 = (a == 5) ? [|(int?)|]b : c; + } } - } - """, - """ - class C - { - void M(int a, int b, int c) + """, + """ + class C { - int? f1 = (a == 5) ? b : c; + void M(int a, int b, int c) + { + int? f1 = (a == 5) ? b : c; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] - public async Task DoNotRemoveNecessaryWideningNullableCastInConditional3() - { - var source = """ - class C - { - void M(int a, int b, int c) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] + public async Task DoNotRemoveNecessaryWideningNullableCastInConditional3() + { + var source = """ + class C { - var f1 = (a == 5) ? (int?)b : c; + void M(int a, int b, int c) + { + var f1 = (a == 5) ? (int?)b : c; + } } - } - """; + """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] - public async Task DoRemoveUnnecessaryWideningConstantCastInConditionalWithDefault3() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class C - { - void M(int a, int b, int c) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] + public async Task DoRemoveUnnecessaryWideningConstantCastInConditionalWithDefault3() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class C { - long f1 = (a == 5) ? [|(long)|]0 : default; + void M(int a, int b, int c) + { + long f1 = (a == 5) ? [|(long)|]0 : default; + } } - } - """, - """ - class C - { - void M(int a, int b, int c) + """, + """ + class C { - long f1 = (a == 5) ? 0 : default; + void M(int a, int b, int c) + { + long f1 = (a == 5) ? 0 : default; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] - public async Task DoNotRemoveNnecessaryWideningConstantCastInConditionalWithDefault3() - { - var source = """ - class C - { - void M(int a, int b, int c) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] + public async Task DoNotRemoveNnecessaryWideningConstantCastInConditionalWithDefault3() + { + var source = """ + class C { - var f1 = (a == 5) ? (long)0 : default; + void M(int a, int b, int c) + { + var f1 = (a == 5) ? (long)0 : default; + } } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] - public async Task DoRemoveUnnecessaryWideningConstantCastInConditionalWithDefault4() - { - await VerifyCS.VerifyCodeFixAsync( - """ - class C - { - void M(int a, int b, int c) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] + public async Task DoRemoveUnnecessaryWideningConstantCastInConditionalWithDefault4() + { + await VerifyCS.VerifyCodeFixAsync( + """ + class C { - long f1 = (a == 5) ? [|(long)|]b : default; + void M(int a, int b, int c) + { + long f1 = (a == 5) ? [|(long)|]b : default; + } } - } - """, - """ - class C - { - void M(int a, int b, int c) + """, + """ + class C { - long f1 = (a == 5) ? b : default; + void M(int a, int b, int c) + { + long f1 = (a == 5) ? b : default; + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] - public async Task DoNotRemoveNecessaryWideningConstantCastInConditionalWithDefault4() - { - var source = """ - class C - { - void M(int a, int b, int c) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] + public async Task DoNotRemoveNecessaryWideningConstantCastInConditionalWithDefault4() + { + var source = """ + class C { - var f1 = (a == 5) ? (long)b : default; + void M(int a, int b, int c) + { + var f1 = (a == 5) ? (long)b : default; + } } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] - public async Task DoNotRemoveNecessaryWideningNullableConstantCastInConditionalWithDefault3() - { - var source = """ - class C - { - void M(int a, int b, int c) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] + public async Task DoNotRemoveNecessaryWideningNullableConstantCastInConditionalWithDefault3() + { + var source = """ + class C { - int? f1 = (a == 5) ? (int?)0 : default; + void M(int a, int b, int c) + { + int? f1 = (a == 5) ? (int?)0 : default; + } } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] - public async Task DoNotRemoveNecessaryWideningNullableCastInConditionalWithDefault3() - { - var source = """ - class C - { - void M(int a, int b, int c) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] + public async Task DoNotRemoveNecessaryWideningNullableCastInConditionalWithDefault3() + { + var source = """ + class C { - int? f1 = (a == 5) ? (int?)b : default; + void M(int a, int b, int c) + { + int? f1 = (a == 5) ? (int?)b : default; + } } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/56938")] - public async Task CanRemoveDoubleNullableNumericCast1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/56938")] + public async Task CanRemoveDoubleNullableNumericCast1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - class Program - { - static void Main() + class Program { - Console.WriteLine((int)(float?)[|(int?)|]2147483647); // Prints -2147483648 + static void Main() + { + Console.WriteLine((int)(float?)[|(int?)|]2147483647); // Prints -2147483648 + } } - } - """, - """ - using System; + """, + """ + using System; - class Program - { - static void Main() + class Program { - Console.WriteLine((int)(float?)2147483647); // Prints -2147483648 + static void Main() + { + Console.WriteLine((int)(float?)2147483647); // Prints -2147483648 + } } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/56938")] - public async Task CanRemoveTripleNullableNumericCast1() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/56938")] + public async Task CanRemoveTripleNullableNumericCast1() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - class Program - { - static void Main() + class Program { - Console.WriteLine((int)(double?)[|(long?)|][|(int?)|]1); + static void Main() + { + Console.WriteLine((int)(double?)[|(long?)|][|(int?)|]1); + } } - } - """, - """ - using System; + """, + """ + using System; - class Program - { - static void Main() + class Program { - Console.WriteLine((int)(double?)1); + static void Main() + { + Console.WriteLine((int)(double?)1); + } } - } - """); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] - public async Task DoNotRemoveMultipleNullableCastsThroughUserDefinedConversions1() - { - var source = """ - struct A - { - } + """); + } - struct B - { - public static implicit operator A(B b) => default; - public static implicit operator B(int a) => default; - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] + public async Task DoNotRemoveMultipleNullableCastsThroughUserDefinedConversions1() + { + var source = """ + struct A + { + } - class P - { - void M() + struct B { - var v = (A?)(B?)0; + public static implicit operator A(B b) => default; + public static implicit operator B(int a) => default; } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] - public async Task DoNotRemoveMultipleNullableCastsThroughUserDefinedConversions2() - { - var source = """ - struct A - { - } + class P + { + void M() + { + var v = (A?)(B?)0; + } + } + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - struct B - { - public static implicit operator A(B b) => default; - public static implicit operator B(int a) => default; - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] + public async Task DoNotRemoveMultipleNullableCastsThroughUserDefinedConversions2() + { + var source = """ + struct A + { + } - class P - { - void M() + struct B { - var v = (A?)(B)0; + public static implicit operator A(B b) => default; + public static implicit operator B(int a) => default; } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] - public async Task DoNotRemoveMultipleCastsThroughUserDefinedConversions2() - { - var source = """ - struct A - { - } + class P + { + void M() + { + var v = (A?)(B)0; + } + } + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - struct B - { - public static implicit operator A(B b) => default; - public static implicit operator B(int a) => default; - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/57064")] + public async Task DoNotRemoveMultipleCastsThroughUserDefinedConversions2() + { + var source = """ + struct A + { + } - class P - { - void M() + struct B { - var v = (A)(B)0; + public static implicit operator A(B b) => default; + public static implicit operator B(int a) => default; } - } - """; - await VerifyCS.VerifyCodeFixAsync(source, source); - } - [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/58171")] - [CombinatorialData] - public async Task DoNotRemoveMethodGroupToSpecificDelegateType(LanguageVersion version) - { - var source = """ - using System; + class P + { + void M() + { + var v = (A)(B)0; + } + } + """; + await VerifyCS.VerifyCodeFixAsync(source, source); + } - class KeyEventArgs : EventArgs - { - } + [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/58171")] + [CombinatorialData] + public async Task DoNotRemoveMethodGroupToSpecificDelegateType(LanguageVersion version) + { + var source = """ + using System; - delegate void KeyEventHandler(object sender, KeyEventArgs e); + class KeyEventArgs : EventArgs + { + } - class C - { + delegate void KeyEventHandler(object sender, KeyEventArgs e); - void M() + class C { - AddHandler((KeyEventHandler)HandleSymbolKindsPreviewKeyDown); + + void M() + { + AddHandler((KeyEventHandler)HandleSymbolKindsPreviewKeyDown); + } + + void HandleSymbolKindsPreviewKeyDown(object sender, KeyEventArgs e) { } + void AddHandler(Delegate handler) { } } + """; + await new VerifyCS.Test + { + TestCode = source, + FixedCode = source, + LanguageVersion = version, + }.RunAsync(); + } - void HandleSymbolKindsPreviewKeyDown(object sender, KeyEventArgs e) { } - void AddHandler(Delegate handler) { } - } - """; - await new VerifyCS.Test + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58095")] + public async Task DoNotRemoveNullableCastsInTuples() { - TestCode = source, - FixedCode = source, - LanguageVersion = version, - }.RunAsync(); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58095")] - public async Task DoNotRemoveNullableCastsInTuples() - { - var source = """ - using System.Diagnostics; + var source = """ + using System.Diagnostics; - class C - { - void M() + class C { - var (isEdge, moreOnes) = (true, false); + void M() + { + var (isEdge, moreOnes) = (true, false); - char? expected_a = isEdge ? null : moreOnes ? '1' : '0'; - char? expected_b = isEdge ? null : moreOnes ? '0' : '1'; + char? expected_a = isEdge ? null : moreOnes ? '1' : '0'; + char? expected_b = isEdge ? null : moreOnes ? '0' : '1'; - (char? expected_a_01, char? expected_b_01) = isEdge ? default : moreOnes ? ((char?)'1', (char?)'0') : ('0', '1'); - (char? expected_a_02, char? expected_b_02) = isEdge ? default : moreOnes ? ('1', '0') : ('0', '1'); + (char? expected_a_01, char? expected_b_01) = isEdge ? default : moreOnes ? ((char?)'1', (char?)'0') : ('0', '1'); + (char? expected_a_02, char? expected_b_02) = isEdge ? default : moreOnes ? ('1', '0') : ('0', '1'); - Debug.Assert(expected_a == expected_a_01 && expected_a == expected_a_02); - Debug.Assert(expected_b == expected_b_01 && expected_b == expected_b_02); + Debug.Assert(expected_a == expected_a_01 && expected_a == expected_a_02); + Debug.Assert(expected_b == expected_b_01 && expected_b == expected_b_02); + } } - } - """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49954")] - public async Task DoNotRemoveNullableDefaultCast1() - { - var source = """ - using System; - - class C + """; + await new VerifyCS.Test { - protected bool? IsNewResource() => - Boolean.TryParse("", out var b) ? b : (bool?)default; - } - """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - }.RunAsync(); - } + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34509")] - public async Task DoNotRemoveNullableDefaultCast2() - { - var source = """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49954")] + public async Task DoNotRemoveNullableDefaultCast1() + { + var source = """ + using System; - class C + class C + { + protected bool? IsNewResource() => + Boolean.TryParse("", out var b) ? b : (bool?)default; + } + """; + await new VerifyCS.Test { - static long? TestParse(string val) => long.TryParse(val, out var parseResult) ? (long?)parseResult : default; - } - """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + TestCode = source, + FixedCode = source, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49690")] - public async Task DoNotRemoveNullableGenericCast() - { - var source = """ - #nullable enable - - using System.Collections.Generic; - using System.Linq; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34509")] + public async Task DoNotRemoveNullableDefaultCast2() + { + var source = """ + using System; - class C - { - static IEnumerable DoThis(IEnumerable notreallynull) + class C { - return notreallynull.Where(s => s is not null) as IEnumerable; + static long? TestParse(string val) => long.TryParse(val, out var parseResult) ? (long?)parseResult : default; } - } - """; - await new VerifyCS.Test + """; + await new VerifyCS.Test + { + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49690")] + public async Task DoNotRemoveNullableGenericCast() { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + var source = """ + #nullable enable - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/45925")] - public async Task DoNotRemoveNecesssaryPatternCasts1() - { - var source = """ - using System; + using System.Collections.Generic; + using System.Linq; - class C - { - bool M(object obj) + class C { - return obj is 0 or (uint)0 or (long)0 or (ulong)0 or (short)0 or (ushort)0 or (byte)0 or (sbyte)0 or (float)0 - or (double)0 or (decimal)0 or (AttributeTargets)0; + static IEnumerable DoThis(IEnumerable notreallynull) + { + return notreallynull.Where(s => s is not null) as IEnumerable; + } } - } - """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + """; + await new VerifyCS.Test + { + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37473")] - public async Task DoNotRemoveNecesssaryCastInTupleWrappedInObject1() - { - var source = """ - using System.Collections.Generic; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/45925")] + public async Task DoNotRemoveNecesssaryPatternCasts1() + { + var source = """ + using System; - public class C - { - public IEnumerable Bar() + class C { - yield return ("test", (decimal?)1.23); + bool M(object obj) + { + return obj is 0 or (uint)0 or (long)0 or (ulong)0 or (short)0 or (ushort)0 or (byte)0 or (sbyte)0 or (float)0 + or (double)0 or (decimal)0 or (AttributeTargets)0; + } } - } - """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + """; + await new VerifyCS.Test + { + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/33143")] - public async Task DoNotRemoveNecesssaryCastInTupleWrappedInObject2() - { - var source = """ - using System.Collections.Generic; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37473")] + public async Task DoNotRemoveNecesssaryCastInTupleWrappedInObject1() + { + var source = """ + using System.Collections.Generic; - public class C - { - void M() + public class C { - object x = (true, (IEnumerable)new int[0]); + public IEnumerable Bar() + { + yield return ("test", (decimal?)1.23); + } } - } - """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + """; + await new VerifyCS.Test + { + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/33043")] - public async Task DoNotRemoveNecesssaryCastInIsNullCheck1() - { - var source = """ - using System.Collections.Generic; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/33143")] + public async Task DoNotRemoveNecesssaryCastInTupleWrappedInObject2() + { + var source = """ + using System.Collections.Generic; - public class C - { - void M() + public class C { - if ((int?)1 is null) + void M() { + object x = (true, (IEnumerable)new int[0]); } } - } - """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + """; + await new VerifyCS.Test + { + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20617")] - public async Task DoNotRemoveNecesssaryBitwiseNotOnUnsignedValue1() - { - var source = """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/33043")] + public async Task DoNotRemoveNecesssaryCastInIsNullCheck1() + { + var source = """ + using System.Collections.Generic; - public class C - { - public static void MethodName() + public class C { - const long x = ~(long)~1U; - Console.WriteLine(x); + void M() + { + if ((int?)1 is null) + { + } + } } - } - """; - await new VerifyCS.Test + """; + await new VerifyCS.Test + { + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20617")] + public async Task DoNotRemoveNecesssaryBitwiseNotOnUnsignedValue1() { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + var source = """ + using System; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11008")] - public async Task DoNotRemoveCastThatPreventsOverflowInChecked1() - { - var source = """ - static class Program + public class C + { + public static void MethodName() + { + const long x = ~(long)~1U; + Console.WriteLine(x); + } + } + """; + await new VerifyCS.Test { - static readonly long x = -(long)int.MinValue; - } - """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34553")] - public async Task DoNotRemoveCastThatPreventsOverflowInChecked2() - { - var source = """ - using System; - class Program - { - void M() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11008")] + public async Task DoNotRemoveCastThatPreventsOverflowInChecked1() + { + var source = """ + static class Program { - Int32 input32 = Int32.MinValue; - Int64 output64_a = checked(-input32); - Int64 output64_b = checked(-(Int64)input32); + static readonly long x = -(long)int.MinValue; } - } - """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11008")] - public async Task DoNotRemoveCastFromIntToNullableEnum1() - { - var source = """ - enum E + """; + await new VerifyCS.Test { - } + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - class Program - { - void M() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/34553")] + public async Task DoNotRemoveCastThatPreventsOverflowInChecked2() + { + var source = """ + using System; + class Program { - int? num = 1; - string s = ((E?)num)?.ToString().Replace('a', 'b'); + void M() + { + Int32 input32 = Int32.MinValue; + Int64 output64_a = checked(-input32); + Int64 output64_b = checked(-(Int64)input32); + } } - } - """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11008")] - public async Task DoNotRemoveWideningCastInBitwiseOr1() - { - var source = """ - class C + """; + await new VerifyCS.Test { - public uint fn1(sbyte a, sbyte b) + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11008")] + public async Task DoNotRemoveCastFromIntToNullableEnum1() + { + var source = """ + enum E { - return (uint)((a << 8) | (int)b); } - } - """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/32773")] - public async Task DoNotRemoveWideningCastInBitwiseOr2() - { - var source = """ - class C - { - public void fn1(int start, int end) + class Program { - var bounds = (((long)end) << 32) | ((long)start); + void M() + { + int? num = 1; + string s = ((E?)num)?.ToString().Replace('a', 'b'); + } } - } - """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25165")] - public async Task DoNotRemoveCastInIllegalDelegateCast() - { - var source = """ - using System; - public delegate void DoSomething(); - - public class Code + """; + await new VerifyCS.Test { - private Action _f; - public Code(DoSomething f) + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11008")] + public async Task DoNotRemoveWideningCastInBitwiseOr1() + { + var source = """ + class C { - Action doNothing = (() => {}); - _f = f ?? {|CS0030:(DoSomething)doNothing|}; + public uint fn1(sbyte a, sbyte b) + { + return (uint)((a << 8) | (int)b); + } } - } - """; - await new VerifyCS.Test + """; + await new VerifyCS.Test + { + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/32773")] + public async Task DoNotRemoveWideningCastInBitwiseOr2() { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + var source = """ + class C + { + public void fn1(int start, int end) + { + var bounds = (((long)end) << 32) | ((long)start); + } + } + """; + await new VerifyCS.Test + { + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/31303")] - public async Task DoNotRemoveUnsignedCastInBitwiseNot1() - { - var source = """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/25165")] + public async Task DoNotRemoveCastInIllegalDelegateCast() + { + var source = """ + using System; + public delegate void DoSomething(); - public class Code - { - static void CheckRedundantCast() + public class Code { - ulong number1 = 0xFFFFFFFFFFFFFFFFL; - uint number2 = 0xFF; - ulong myResult = number1 & ~(ulong)number2; + private Action _f; + public Code(DoSomething f) + { + Action doNothing = (() => {}); + _f = f ?? {|CS0030:(DoSomething)doNothing|}; + } } - } - """; - await new VerifyCS.Test + """; + await new VerifyCS.Test + { + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/31303")] + public async Task DoNotRemoveUnsignedCastInBitwiseNot1() { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + var source = """ + using System; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36755")] - public async Task DoNotRemoveNecessaryCastInSwitchExpressionArm1() - { - var source = """ - class Program - { - void M() + public class Code { - string numberString = "One"; - Numbers? number = numberString switch + static void CheckRedundantCast() { - "One" => (Numbers?)Numbers.One, - "Two" => Numbers.Two, - _ => null, - }; + ulong number1 = 0xFFFFFFFFFFFFFFFFL; + uint number2 = 0xFF; + ulong myResult = number1 & ~(ulong)number2; + } } - } - - enum Numbers + """; + await new VerifyCS.Test { - One, - Two - } - """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36782")] - public async Task DoNotRemoveNecessaryCastWithOverloadedNegationAndImplicitConversion1() - { - var source = """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36755")] + public async Task DoNotRemoveNecessaryCastInSwitchExpressionArm1() + { + var source = """ + class Program + { + void M() + { + string numberString = "One"; + Numbers? number = numberString switch + { + "One" => (Numbers?)Numbers.One, + "Two" => Numbers.Two, + _ => null, + }; + } + } - namespace WrongRedundantCastWarning + enum Numbers + { + One, + Two + } + """; + await new VerifyCS.Test { - struct Flag - { - public Flag(int value) => this.Value = value; + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - public int Value { get; } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/36782")] + public async Task DoNotRemoveNecessaryCastWithOverloadedNegationAndImplicitConversion1() + { + var source = """ + using System; - // This cast is wrongly reported as redundant - public static FlagSet operator ~(Flag flag) => ~(FlagSet)flag; - } + namespace WrongRedundantCastWarning + { + struct Flag + { + public Flag(int value) => this.Value = value; - struct FlagSet - { - public FlagSet(int value) => this.Value = value; + public int Value { get; } - public int Value { get; } + // This cast is wrongly reported as redundant + public static FlagSet operator ~(Flag flag) => ~(FlagSet)flag; + } - public static implicit operator FlagSet(Flag flag) => new FlagSet(flag.Value); + struct FlagSet + { + public FlagSet(int value) => this.Value = value; - public static FlagSet operator ~(FlagSet flagSet) => new FlagSet(~flagSet.Value); - } + public int Value { get; } - class Program - { - static readonly Flag One = new Flag(1); - static readonly Flag Two = new Flag(2); + public static implicit operator FlagSet(Flag flag) => new FlagSet(flag.Value); - static void Main(string[] args) - { - var flipped = ~Two; + public static FlagSet operator ~(FlagSet flagSet) => new FlagSet(~flagSet.Value); + } - Console.WriteLine(flipped.Value); - } - } - } - """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + class Program + { + static readonly Flag One = new Flag(1); + static readonly Flag Two = new Flag(2); - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37041")] - public async Task DoNotRemoveNecessaryMethodGroupToDelegateCast1() - { - var source = """ - using System; - using System.Collections.Generic; + static void Main(string[] args) + { + var flipped = ~Two; - namespace RedundantCast + Console.WriteLine(flipped.Value); + } + } + } + """; + await new VerifyCS.Test { - class Program - { - class A { } - class B : A { } + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - B Goo() { return null; } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/37041")] + public async Task DoNotRemoveNecessaryMethodGroupToDelegateCast1() + { + var source = """ + using System; + using System.Collections.Generic; - static void Main() + namespace RedundantCast + { + class Program { - (new Program()). Run(); - } + class A { } + class B : A { } - void Run() - { - var list = new List>(); - list. Add((Func) Goo); - switch (list[0]) + B Goo() { return null; } + + static void Main() + { + (new Program()). Run(); + } + + void Run() { - case Func value: Console.WriteLine("B"); break; - case Func value: Console.WriteLine("A"); break; + var list = new List>(); + list. Add((Func) Goo); + switch (list[0]) + { + case Func value: Console.WriteLine("B"); break; + case Func value: Console.WriteLine("A"); break; + } } } } - } - """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + """; + await new VerifyCS.Test + { + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/54388")] - public async Task DoNotRemoveCastFromIntToDecimal() - { - var source = """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/54388")] + public async Task DoNotRemoveCastFromIntToDecimal() + { + var source = """ + using System; - class Program - { - void M() + class Program { - X v = new((decimal)-1); + void M() + { + X v = new((decimal)-1); + } } - } - class X + class X + { + public X(decimal d) { } + public X(double d) { } + } + """; + await new VerifyCS.Test { - public X(decimal d) { } - public X(double d) { } - } - """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/33285")] - public async Task DoNotRemoveNullableToStructCast1() - { - var source = """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/33285")] + public async Task DoNotRemoveNullableToStructCast1() + { + var source = """ + using System; - namespace System - { - public readonly struct ReadOnlyMemory : IEquatable> + namespace System { - private readonly object _dummy; - private readonly int _dummyPrimitive; - public static ReadOnlyMemory Empty => throw new NotImplementedException(); - public bool IsEmpty => throw new NotImplementedException(); - public int Length => throw new NotImplementedException(); - public ReadOnlyMemory(T[] array) => throw new NotImplementedException(); - public ReadOnlyMemory(T[] array, int start, int length) => throw new NotImplementedException(); - public bool Equals(ReadOnlyMemory other) => throw new NotImplementedException(); + public readonly struct ReadOnlyMemory : IEquatable> + { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public static ReadOnlyMemory Empty => throw new NotImplementedException(); + public bool IsEmpty => throw new NotImplementedException(); + public int Length => throw new NotImplementedException(); + public ReadOnlyMemory(T[] array) => throw new NotImplementedException(); + public ReadOnlyMemory(T[] array, int start, int length) => throw new NotImplementedException(); + public bool Equals(ReadOnlyMemory other) => throw new NotImplementedException(); + } + + public class Lazy + { + public bool IsValueCreated => throw new NotImplementedException(); + public T Value => throw new NotImplementedException(); + public Lazy() => throw new NotImplementedException(); + public Lazy(bool isThreadSafe) => throw new NotImplementedException(); + public Lazy(Func valueFactory) => throw new NotImplementedException(); + public Lazy(Func valueFactory, bool isThreadSafe) => throw new NotImplementedException(); + public Lazy(T value) => throw new NotImplementedException(); + } } - public class Lazy + class C { - public bool IsValueCreated => throw new NotImplementedException(); - public T Value => throw new NotImplementedException(); - public Lazy() => throw new NotImplementedException(); - public Lazy(bool isThreadSafe) => throw new NotImplementedException(); - public Lazy(Func valueFactory) => throw new NotImplementedException(); - public Lazy(Func valueFactory, bool isThreadSafe) => throw new NotImplementedException(); - public Lazy(T value) => throw new NotImplementedException(); + private C(ReadOnlyMemory? buffer = null) + { + var v = new Lazy>((ReadOnlyMemory)buffer); + } } - } - - class C + """; + await new VerifyCS.Test { - private C(ReadOnlyMemory? buffer = null) + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58718")] + public async Task FunctionPointerWithImplicitOperator() + { + var source = """ + unsafe { - var v = new Lazy>((ReadOnlyMemory)buffer); + PointerDelegate dp = (PointerDelegate)(&Mtd); } - } - """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58718")] - public async Task FunctionPointerWithImplicitOperator() - { - var source = """ - unsafe - { - PointerDelegate dp = (PointerDelegate)(&Mtd); - } + static int Mtd(int arg) => arg; - static int Mtd(int arg) => arg; + public readonly struct PointerDelegate + { + private unsafe readonly delegate* _pointer; - public readonly struct PointerDelegate - { - private unsafe readonly delegate* _pointer; + public unsafe PointerDelegate(delegate* pointer) + { + this._pointer = pointer; + } - public unsafe PointerDelegate(delegate* pointer) - { - this._pointer = pointer; - } + public TResult Invoke(T param) + { + unsafe + { + return this._pointer(param); + } + } - public TResult Invoke(T param) - { - unsafe + public unsafe static implicit operator PointerDelegate(delegate* pointer) { - return this._pointer(param); + return new(pointer); } } - - public unsafe static implicit operator PointerDelegate(delegate* pointer) + """; + await new VerifyCS.Test + { + TestState = { - return new(pointer); - } - } - """; - await new VerifyCS.Test + OutputKind = OutputKind.ConsoleApplication, + }, + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58709")] + public async Task NotOnNarrowingIntCastInTernary() { - TestState = - { - OutputKind = OutputKind.ConsoleApplication, - }, - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58709")] - public async Task NotOnNarrowingIntCastInTernary() - { - var source = """ - class C - { - protected sbyte ExtractInt8(object data) + var source = """ + class C { - return (data is sbyte value) ? value : (sbyte)0; + protected sbyte ExtractInt8(object data) + { + return (data is sbyte value) ? value : (sbyte)0; + } } - } - """; - await new VerifyCS.Test - { - TestCode = source, - FixedCode = source, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + """; + await new VerifyCS.Test + { + TestCode = source, + FixedCode = source, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58898")] - public async Task SameNullableTypeOnBothSidesOfConditional1() - { - await new VerifyCS.Test + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58898")] + public async Task SameNullableTypeOnBothSidesOfConditional1() { - TestCode = """ - using System; - - class C + await new VerifyCS.Test { - void M() + TestCode = """ + using System; + + class C { - var id = true ? [|(Guid?)|]Guid.NewGuid() : [|(Guid?)|]Guid.Empty; + void M() + { + var id = true ? [|(Guid?)|]Guid.NewGuid() : [|(Guid?)|]Guid.Empty; + } } - } - """, - FixedCode = """ - using System; + """, + FixedCode = """ + using System; - class C - { - void M() + class C { - var id = true ? Guid.NewGuid() : (Guid?)Guid.Empty; + void M() + { + var id = true ? Guid.NewGuid() : (Guid?)Guid.Empty; + } } - } - """, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + """, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58898")] - public async Task SameNullableTypeOnBothSidesOfConditional2() - { - await new VerifyCS.Test + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58898")] + public async Task SameNullableTypeOnBothSidesOfConditional2() { - TestCode = """ - using System; - - class C + await new VerifyCS.Test { - void M(Guid g1, Guid? g2) + TestCode = """ + using System; + + class C { - var id = true ? [|(Guid?)|]g1 : g2; + void M(Guid g1, Guid? g2) + { + var id = true ? [|(Guid?)|]g1 : g2; + } } - } - """, - FixedCode = """ - using System; + """, + FixedCode = """ + using System; - class C - { - void M(Guid g1, Guid? g2) + class C { - var id = true ? g1 : g2; + void M(Guid g1, Guid? g2) + { + var id = true ? g1 : g2; + } } - } - """, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + """, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58898")] - public async Task SameNullableTypeOnBothSidesOfConditional3() - { - await new VerifyCS.Test + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58898")] + public async Task SameNullableTypeOnBothSidesOfConditional3() { - TestCode = """ - using System; - - class C + await new VerifyCS.Test { - void M(Guid? g1, Guid g2) + TestCode = """ + using System; + + class C { - var id = true ? g1 : [|(Guid?)|]g2; + void M(Guid? g1, Guid g2) + { + var id = true ? g1 : [|(Guid?)|]g2; + } } - } - """, - FixedCode = """ - using System; + """, + FixedCode = """ + using System; - class C - { - void M(Guid? g1, Guid g2) + class C { - var id = true ? g1 : g2; + void M(Guid? g1, Guid g2) + { + var id = true ? g1 : g2; + } } - } - """, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + """, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58898")] - public async Task SameNullableTypeOnBothSidesOfConditional4() - { - await new VerifyCS.Test + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58898")] + public async Task SameNullableTypeOnBothSidesOfConditional4() { - TestCode = """ - using System; - - class C + await new VerifyCS.Test { - void M(Guid g1, Guid g2) + TestCode = """ + using System; + + class C { - Guid? id = true ? [|(Guid?)|]g1 : g2; + void M(Guid g1, Guid g2) + { + Guid? id = true ? [|(Guid?)|]g1 : g2; + } } - } - """, - FixedCode = """ - using System; + """, + FixedCode = """ + using System; - class C - { - void M(Guid g1, Guid g2) + class C { - Guid? id = true ? g1 : g2; + void M(Guid g1, Guid g2) + { + Guid? id = true ? g1 : g2; + } } - } - """, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + """, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58898")] - public async Task SameNullableTypeOnBothSidesOfConditional5() - { - await new VerifyCS.Test + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58898")] + public async Task SameNullableTypeOnBothSidesOfConditional5() { - TestCode = """ - using System; - - class C + await new VerifyCS.Test { - void M(Guid g1, Guid g2) + TestCode = """ + using System; + + class C { - Guid? id = true ? g1 : [|(Guid?)|]g2; + void M(Guid g1, Guid g2) + { + Guid? id = true ? g1 : [|(Guid?)|]g2; + } } - } - """, - FixedCode = """ - using System; + """, + FixedCode = """ + using System; - class C - { - void M(Guid g1, Guid g2) + class C { - Guid? id = true ? g1 : g2; + void M(Guid g1, Guid g2) + { + Guid? id = true ? g1 : g2; + } } - } - """, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + """, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58898")] - public async Task SameNullableTypeOnBothSidesOfConditional6() - { - await new VerifyCS.Test + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58898")] + public async Task SameNullableTypeOnBothSidesOfConditional6() { - TestCode = """ - using System; - - class C + await new VerifyCS.Test { - void M(Guid g1, Guid g2) + TestCode = """ + using System; + + class C { - Guid? id = true ? [|(Guid?)|]g1 : [|(Guid?)|]g2; + void M(Guid g1, Guid g2) + { + Guid? id = true ? [|(Guid?)|]g1 : [|(Guid?)|]g2; + } } - } - """, - FixedCode = """ - using System; + """, + FixedCode = """ + using System; - class C - { - void M(Guid g1, Guid g2) + class C { - Guid? id = true ? g1 : g2; + void M(Guid g1, Guid g2) + { + Guid? id = true ? g1 : g2; + } } - } - """, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + """, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58804")] - public async Task ConvertingMethodGroupToObject_CastIsNecessary() - { - var code = """ - class C - { - static object M(object o) + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58804")] + public async Task ConvertingMethodGroupToObject_CastIsNecessary() + { + var code = """ + class C { - return (object)o.ToString; + static object M(object o) + { + return (object)o.ToString; + } } - } - """; - await new VerifyCS.Test - { - TestCode = code, - FixedCode = code, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + """; + await new VerifyCS.Test + { + TestCode = code, + FixedCode = code, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58804")] - public async Task ConvertingMethodGroupToObject_CastIsNecessary2() - { - var code = """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58804")] + public async Task ConvertingMethodGroupToObject_CastIsNecessary2() + { + var code = """ + using System; - class C - { - static T M(object o) + class C { - return (T)(object)o.ToString; - } + static T M(object o) + { + return (T)(object)o.ToString; + } - static T M2(object o) where T : Delegate - { - return (T)(object)o.ToString; + static T M2(object o) where T : Delegate + { + return (T)(object)o.ToString; + } } - } - """; - await new VerifyCS.Test - { - TestCode = code, - FixedCode = code, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } + """; + await new VerifyCS.Test + { + TestCode = code, + FixedCode = code, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/58804")] - [InlineData("Delegate")] - [InlineData("MulticastDelegate")] - [InlineData("Func")] - public async Task ConvertingMethodGroupToObject_CastIsUnnecessary(string type) - { - var code = $@" + [Theory, WorkItem("https://github.com/dotnet/roslyn/issues/58804")] + [InlineData("Delegate")] + [InlineData("MulticastDelegate")] + [InlineData("Func")] + public async Task ConvertingMethodGroupToObject_CastIsUnnecessary(string type) + { + var code = $@" using System; class C @@ -13018,7 +13018,7 @@ class C }} }} "; - var fixedCode = $@" + var fixedCode = $@" using System; class C @@ -13029,728 +13029,608 @@ class C }} }} "; - await new VerifyCS.Test - { - TestCode = code, - FixedCode = fixedCode, - LanguageVersion = LanguageVersion.CSharp10, - NumberOfIncrementalIterations = 2, - NumberOfFixAllIterations = 2, - }.RunAsync(); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58804")] - public async Task ConvertingMethodGroupToObject_CastIsUnnecessary2() - { - var code = """ - using System; + await new VerifyCS.Test + { + TestCode = code, + FixedCode = fixedCode, + LanguageVersion = LanguageVersion.CSharp10, + NumberOfIncrementalIterations = 2, + NumberOfFixAllIterations = 2, + }.RunAsync(); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/58804")] + public async Task ConvertingMethodGroupToObject_CastIsUnnecessary2() + { + var code = """ + using System; - class C - { - static Delegate M(object o) + class C { - return (Delegate)[|(object)|]o.ToString; + static Delegate M(object o) + { + return (Delegate)[|(object)|]o.ToString; + } } - } - """; - var fixedCode = """ - using System; + """; + var fixedCode = """ + using System; - class C - { - static Delegate M(object o) + class C { - return o.ToString; + static Delegate M(object o) + { + return o.ToString; + } } - } - """; - await new VerifyCS.Test - { - TestCode = code, - FixedCode = fixedCode, - LanguageVersion = LanguageVersion.CSharp10, - NumberOfIncrementalIterations = 2, - NumberOfFixAllIterations = 2, - }.RunAsync(); - } + """; + await new VerifyCS.Test + { + TestCode = code, + FixedCode = fixedCode, + LanguageVersion = LanguageVersion.CSharp10, + NumberOfIncrementalIterations = 2, + NumberOfFixAllIterations = 2, + }.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/60248")] - public async Task RemoveCastInTopLevelPrograms() - { - var test = new VerifyCS.Test() - { - TestCode = """ - int x = 1; - int y = [|(int)|]x; - """, - FixedCode = """ - int x = 1; - int y = x; - """, - LanguageVersion = LanguageVersion.CSharp10, - TestState = + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/60248")] + public async Task RemoveCastInTopLevelPrograms() + { + var test = new VerifyCS.Test() { - OutputKind = OutputKind.ConsoleApplication, - }, - }; + TestCode = """ + int x = 1; + int y = [|(int)|]x; + """, + FixedCode = """ + int x = 1; + int y = x; + """, + LanguageVersion = LanguageVersion.CSharp10, + TestState = + { + OutputKind = OutputKind.ConsoleApplication, + }, + }; - await test.RunAsync(); - } + await test.RunAsync(); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/60292")] - public async Task KeepNecessaryExplicitNullableCast() - { - var code = """ - using System; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/60292")] + public async Task KeepNecessaryExplicitNullableCast() + { + var code = """ + using System; - namespace ConsoleApp1 - { - internal class Program + namespace ConsoleApp1 { - static void Main(string[] args) + internal class Program { - for (var i = 0; i < 100; i++) + static void Main(string[] args) { - bool should = Should(); - Test? test = ShouldTest(); - int? testId = should ? (int?)test : null; // incorrect IDE0004 + for (var i = 0; i < 100; i++) + { + bool should = Should(); + Test? test = ShouldTest(); + int? testId = should ? (int?)test : null; // incorrect IDE0004 + } } - } - private static bool Should() - { - return new Random().Next() % 2 == 0; + private static bool Should() + { + return new Random().Next() % 2 == 0; + } + + private static Test? ShouldTest() + { + var value = new Random().Next(3); + if (Enum.IsDefined(typeof(Test), value)) + return (Test)value; + + return null; + } } - private static Test? ShouldTest() + public enum Test { - var value = new Random().Next(3); - if (Enum.IsDefined(typeof(Test), value)) - return (Test)value; - - return null; + Foo = 1, + Bar = 2, } } + """; + await new VerifyCS.Test + { + TestCode = code, + FixedCode = code, + LanguageVersion = LanguageVersion.CSharp10, + }.RunAsync(); + } - public enum Test - { - Foo = 1, - Bar = 2, - } - } - """; - await new VerifyCS.Test + [Fact, WorkItem(64346, "https://github.com/dotnet/roslyn/issues/61346")] + public async Task CanRemoveCastToObjectInStringInterpolation_NullableDisable() { - TestCode = code, - FixedCode = code, - LanguageVersion = LanguageVersion.CSharp10, - }.RunAsync(); - } - - [Fact, WorkItem(64346, "https://github.com/dotnet/roslyn/issues/61346")] - public async Task CanRemoveCastToObjectInStringInterpolation_NullableDisable() - { - var code = """ - #nullable disable + var code = """ + #nullable disable - class C - { - void M() + class C { - var v = $"{[|(object)|]0}"; + void M() + { + var v = $"{[|(object)|]0}"; + } } - } - """; - var fixedCode = """ - #nullable disable + """; + var fixedCode = """ + #nullable disable - class C - { - void M() + class C { - var v = $"{0}"; + void M() + { + var v = $"{0}"; + } } - } - """; - await VerifyCS.VerifyCodeFixAsync(code, fixedCode); - } + """; + await VerifyCS.VerifyCodeFixAsync(code, fixedCode); + } - [Fact, WorkItem(64346, "https://github.com/dotnet/roslyn/issues/61346")] - public async Task CanRemoveCastToObjectInStringInterpolation_NullableEnable() - { - var code = """ - #nullable enable + [Fact, WorkItem(64346, "https://github.com/dotnet/roslyn/issues/61346")] + public async Task CanRemoveCastToObjectInStringInterpolation_NullableEnable() + { + var code = """ + #nullable enable - class C - { - void M() + class C { - var v = $"{[|(object)|]0}"; + void M() + { + var v = $"{[|(object)|]0}"; + } } - } - """; - var fixedCode = """ - #nullable enable + """; + var fixedCode = """ + #nullable enable - class C - { - void M() + class C { - var v = $"{0}"; + void M() + { + var v = $"{0}"; + } } - } - """; - await VerifyCS.VerifyCodeFixAsync(code, fixedCode); - } + """; + await VerifyCS.VerifyCodeFixAsync(code, fixedCode); + } - [Fact, WorkItem(64346, "https://github.com/dotnet/roslyn/issues/61346")] - public async Task CanRemoveCastToNullableObjectInStringInterpolation() - { - var code = """ - #nullable enable + [Fact, WorkItem(64346, "https://github.com/dotnet/roslyn/issues/61346")] + public async Task CanRemoveCastToNullableObjectInStringInterpolation() + { + var code = """ + #nullable enable - class C - { - void M() + class C { - var v = $"{[|(object?)|]0}"; + void M() + { + var v = $"{[|(object?)|]0}"; + } } - } - """; - var fixedCode = """ - #nullable enable + """; + var fixedCode = """ + #nullable enable - class C - { - void M() + class C { - var v = $"{0}"; + void M() + { + var v = $"{0}"; + } } - } - """; - await VerifyCS.VerifyCodeFixAsync(code, fixedCode); - } + """; + await VerifyCS.VerifyCodeFixAsync(code, fixedCode); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28867")] - public async Task DoNotRemoveNullableCastInConditional() - { - var code = """ - class C - { - void M() + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28867")] + public async Task DoNotRemoveNullableCastInConditional() + { + var code = """ + class C { - int? a = false ? (int?)1 : default; - System.Console.WriteLine(a.HasValue); + void M() + { + int? a = false ? (int?)1 : default; + System.Console.WriteLine(a.HasValue); + } } - } - """; - await VerifyCS.VerifyCodeFixAsync(code, code); - } + """; + await VerifyCS.VerifyCodeFixAsync(code, code); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28867")] - public async Task DoNotRemoveNullableRefCastToVar() - { - var code = """ - #nullable enable - - class Bar - { - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/28867")] + public async Task DoNotRemoveNullableRefCastToVar() + { + var code = """ + #nullable enable - class C - { - void Goo(Bar bar) + class Bar { - var nullableBar = (Bar?)bar; - nullableBar = null; } - } - """; - await VerifyCS.VerifyCodeFixAsync(code, code); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/65005")] - public async Task DoNotRemoveImplicitNullableBoxingCast1() - { - var code = """ - #nullable enable - using System; - - class C - { - void Goo() + class C { - byte? temp = 10; - object box = (int?)temp; - - Console.WriteLine((int?)box); + void Goo(Bar bar) + { + var nullableBar = (Bar?)bar; + nullableBar = null; + } } - } - """; - await VerifyCS.VerifyCodeFixAsync(code, code); - } + """; + await VerifyCS.VerifyCodeFixAsync(code, code); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/65005")] - public async Task DoNotRemoveImplicitNullableBoxingCast2() - { - var code = """ - #nullable enable + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/65005")] + public async Task DoNotRemoveImplicitNullableBoxingCast1() + { + var code = """ + #nullable enable - using System; + using System; - class C - { - void Goo() + class C { - byte? temp = 10; - object? box = (int?)temp; + void Goo() + { + byte? temp = 10; + object box = (int?)temp; - Console.WriteLine((int?)box); + Console.WriteLine((int?)box); + } } - } - """; - await VerifyCS.VerifyCodeFixAsync(code, code); - } + """; + await VerifyCS.VerifyCodeFixAsync(code, code); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/61922")] - public async Task IdentityStructCast1() - { - var code = """ - using System; - public struct S { - public int Field; - public void Increment() => Field++; - public void Print() => Console.WriteLine(Field); - } - public class C { - S s; - - public void M() { - ((S)s).Increment(); // cast causes local copy of s - s.Print(); - } - } - """; - await VerifyCS.VerifyCodeFixAsync(code, code); - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/65005")] + public async Task DoNotRemoveImplicitNullableBoxingCast2() + { + var code = """ + #nullable enable - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/61922")] - public async Task IdentityStructCast2() - { - await VerifyCS.VerifyCodeFixAsync( - """ - using System; + using System; - public class C { - double s; + class C + { + void Goo() + { + byte? temp = 10; + object? box = (int?)temp; - public void M() { - ([|(double)|]s).CompareTo(0); // double is built in. Methods will not mutate it. - Console.WriteLine(s); + Console.WriteLine((int?)box); + } } - } - """, - """ - using System; + """; + await VerifyCS.VerifyCodeFixAsync(code, code); + } - public class C { - double s; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/61922")] + public async Task IdentityStructCast1() + { + var code = """ + using System; + public struct S { + public int Field; + public void Increment() => Field++; + public void Print() => Console.WriteLine(Field); + } + public class C { + S s; - public void M() { - s.CompareTo(0); // double is built in. Methods will not mutate it. - Console.WriteLine(s); + public void M() { + ((S)s).Increment(); // cast causes local copy of s + s.Print(); + } } - } - """); - } + """; + await VerifyCS.VerifyCodeFixAsync(code, code); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/61922")] - public async Task IdentityStructCast3() - { - await VerifyCS.VerifyCodeFixAsync(""" - using System; - public class S { - public int Field; - public void Increment() => Field++; - public void Print() => Console.WriteLine(Field); - } - public class C { - S s; - - public void M() { - ([|(S)|]s).Increment(); // safe to remove since this is not a struct - s.Print(); - } - } - """, """ - using System; - public class S { - public int Field; - public void Increment() => Field++; - public void Print() => Console.WriteLine(Field); - } - public class C { - S s; - - public void M() { - s.Increment(); // safe to remove since this is not a struct - s.Print(); - } - } - """); - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/61922")] + public async Task IdentityStructCast2() + { + await VerifyCS.VerifyCodeFixAsync( + """ + using System; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/61922")] - public async Task IdentityStructCast4() - { - await VerifyCS.VerifyCodeFixAsync(""" - using System; - public readonly struct S - { - public readonly int Field; - public void Increment() { } - public void Print() => Console.WriteLine(Field); - } - public class C { - S s; - - public void M() { - ([|(S)|]s).Increment(); // safe to remove since struct is readonly - s.Print(); - } - } - """, """ - using System; - public readonly struct S - { - public readonly int Field; - public void Increment() { } - public void Print() => Console.WriteLine(Field); - } - public class C { - S s; - - public void M() { - s.Increment(); // safe to remove since struct is readonly - s.Print(); - } - } - """); - } + public class C { + double s; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/61922")] - public async Task IdentityStructCast5() - { - await VerifyCS.VerifyCodeFixAsync(""" - using System; - public struct S - { - public readonly int Field; - public void Increment() { } - public void Print() => Console.WriteLine(Field); - } - public class C { - S s; - - S GetS() => s; - - public void M() { - ([|(S)|]GetS()).Increment(); // safe to remove since not an lvalue. - s.Print(); - } - } - """, """ - using System; - public struct S - { - public readonly int Field; - public void Increment() { } - public void Print() => Console.WriteLine(Field); - } - public class C { - S s; + public void M() { + ([|(double)|]s).CompareTo(0); // double is built in. Methods will not mutate it. + Console.WriteLine(s); + } + } + """, + """ + using System; - S GetS() => s; + public class C { + double s; - public void M() { - GetS().Increment(); // safe to remove since not an lvalue. - s.Print(); + public void M() { + s.CompareTo(0); // double is built in. Methods will not mutate it. + Console.WriteLine(s); + } } - } - """); - } - - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/61922")] - public async Task IdentityStructCast6() - { - await VerifyCS.VerifyCodeFixAsync(""" - using System; - public struct S - { - public readonly int Field; - public readonly void Increment() { } - public void Print() => Console.WriteLine(Field); - } - public class C { - S s; - - public void M() { - ([|(S)|]s).Increment(); // safe to remove since method is readonly - s.Print(); - } - } - """, """ - using System; - public struct S - { - public readonly int Field; - public readonly void Increment() { } - public void Print() => Console.WriteLine(Field); - } - public class C { - S s; - - public void M() { - s.Increment(); // safe to remove since method is readonly - s.Print(); - } - } - """); - } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/61922")] - public async Task IdentityStructCast7() - { - await VerifyCS.VerifyCodeFixAsync(""" - using System; - public struct S - { - public readonly int Field; - public override string ToString() => ""; - public void Print() => Console.WriteLine(Field); - } - public class C { - S s; - - public void M() { - ([|(S)|]s).ToString(); // safe to remove since override of object method - s.Print(); - } - } - """, """ - using System; - public struct S - { - public readonly int Field; - public override string ToString() => ""; - public void Print() => Console.WriteLine(Field); - } - public class C { - S s; - - public void M() { - s.ToString(); // safe to remove since override of object method - s.Print(); - } - } - """); - } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/61922")] + public async Task IdentityStructCast3() + { + await VerifyCS.VerifyCodeFixAsync(""" + using System; + public class S { + public int Field; + public void Increment() => Field++; + public void Print() => Console.WriteLine(Field); + } + public class C { + S s; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/61922")] - public async Task IdentityStructCast8() - { - await VerifyCS.VerifyCodeFixAsync(""" - using System; - public struct S { - public int Field; - public void Increment() => Field++; - public void Print() => Console.WriteLine(Field); - public int Prop => 0; - } - public class C { - S s; - - public void M() { - var v = ([|(S)|]s).Prop; // Safe because we assume non-methods don't mutate - s.Print(); - } - } - """, """ - using System; - public struct S { - public int Field; - public void Increment() => Field++; - public void Print() => Console.WriteLine(Field); - public int Prop => 0; - } - public class C { - S s; - - public void M() { - var v = s.Prop; // Safe because we assume non-methods don't mutate - s.Print(); - } - } - """); - } + public void M() { + ([|(S)|]s).Increment(); // safe to remove since this is not a struct + s.Print(); + } + } + """, """ + using System; + public class S { + public int Field; + public void Increment() => Field++; + public void Print() => Console.WriteLine(Field); + } + public class C { + S s; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/61922")] - public async Task IdentityStructCast9() - { - await VerifyCS.VerifyCodeFixAsync(""" - using System; - public struct S { - public int Field; - public void Increment() => Field++; - public void Print() => Console.WriteLine(Field); - public int Prop => 0; - } - public class C { - S s; - - public void M() { - var v = [|(S)|]s; // Safe because we're not accessing a member - s.Print(); - } - } - """, """ - using System; - public struct S { - public int Field; - public void Increment() => Field++; - public void Print() => Console.WriteLine(Field); - public int Prop => 0; - } - public class C { - S s; - - public void M() { - var v = s; // Safe because we're not accessing a member - s.Print(); - } - } - """); - } + public void M() { + s.Increment(); // safe to remove since this is not a struct + s.Print(); + } + } + """); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/71511")] - public async Task KeepRequiredCastOnCollectionExpression1() - { - await new VerifyCS.Test + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/61922")] + public async Task IdentityStructCast4() { - TestCode = """ - using System.Collections.Generic; + await VerifyCS.VerifyCodeFixAsync(""" + using System; + public readonly struct S + { + public readonly int Field; + public void Increment() { } + public void Print() => Console.WriteLine(Field); + } + public class C { + S s; - public class C + public void M() { + ([|(S)|]s).Increment(); // safe to remove since struct is readonly + s.Print(); + } + } + """, """ + using System; + public readonly struct S { - public IEnumerable M2() => (int[])[1, 2, 3, 4]; + public readonly int Field; + public void Increment() { } + public void Print() => Console.WriteLine(Field); } - """, - LanguageVersion = LanguageVersion.CSharp12, - }.RunAsync(); - } + public class C { + S s; - [Theory, CombinatorialData, WorkItem("https://github.com/dotnet/roslyn/issues/71511")] - public async Task KeepRequiredCastOnCollectionExpression2( - [CombinatorialValues("IEnumerable", "IReadOnlyCollection", "IReadOnlyList")] string type) - { - await new VerifyCS.Test - { - TestCode = $$""" - using System.Collections.Generic; + public void M() { + s.Increment(); // safe to remove since struct is readonly + s.Print(); + } + } + """); + } - public class C + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/61922")] + public async Task IdentityStructCast5() + { + await VerifyCS.VerifyCodeFixAsync(""" + using System; + public struct S { - public {{type}} M2() => (List)[1, 2, 3, 4]; + public readonly int Field; + public void Increment() { } + public void Print() => Console.WriteLine(Field); } - """, - LanguageVersion = LanguageVersion.CSharp12, - }.RunAsync(); - } + public class C { + S s; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/71511")] - public async Task RemoveUnnecessaryCastOnCollectionExpression1() - { - await new VerifyCS.Test - { - TestCode = """ - using System.Collections.Generic; + S GetS() => s; - public class C + public void M() { + ([|(S)|]GetS()).Increment(); // safe to remove since not an lvalue. + s.Print(); + } + } + """, """ + using System; + public struct S { - public int[] M2() => [|(int[])|][1, 2, 3, 4]; + public readonly int Field; + public void Increment() { } + public void Print() => Console.WriteLine(Field); } - """, - FixedCode = """ - using System.Collections.Generic; + public class C { + S s; - public class C - { - public int[] M2() => [1, 2, 3, 4]; + S GetS() => s; + + public void M() { + GetS().Increment(); // safe to remove since not an lvalue. + s.Print(); + } } - """, - LanguageVersion = LanguageVersion.CSharp12, - }.RunAsync(); - } + """); + } - [Theory, CombinatorialData, WorkItem("https://github.com/dotnet/roslyn/issues/71511")] - public async Task RemoveUnnecessaryCastOnCollectionExpression2( - [CombinatorialValues("ICollection", "IList")] string type, - [CombinatorialValues("List", "IList")] string castType) - { - await new VerifyCS.Test + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/61922")] + public async Task IdentityStructCast6() { - TestCode = $$""" - using System.Collections.Generic; - - public class C + await VerifyCS.VerifyCodeFixAsync(""" + using System; + public struct S { - public {{type}} M2() => [|({{castType}})|][1, 2, 3, 4]; + public readonly int Field; + public readonly void Increment() { } + public void Print() => Console.WriteLine(Field); } - """, - FixedCode = $$""" - using System.Collections.Generic; + public class C { + S s; - public class C + public void M() { + ([|(S)|]s).Increment(); // safe to remove since method is readonly + s.Print(); + } + } + """, """ + using System; + public struct S { - public {{type}} M2() => [1, 2, 3, 4]; + public readonly int Field; + public readonly void Increment() { } + public void Print() => Console.WriteLine(Field); } - """, - LanguageVersion = LanguageVersion.CSharp12, - }.RunAsync(); - } + public class C { + S s; - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/71511")] - public async Task RemoveUnnecessaryCastOnCollectionExpression3() - { - await new VerifyCS.Test + public void M() { + s.Increment(); // safe to remove since method is readonly + s.Print(); + } + } + """); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/61922")] + public async Task IdentityStructCast7() { - TestCode = """ + await VerifyCS.VerifyCodeFixAsync(""" using System; - using System.Collections.Generic; + public struct S + { + public readonly int Field; + public override string ToString() => ""; + public void Print() => Console.WriteLine(Field); + } + public class C { + S s; - public class C + public void M() { + ([|(S)|]s).ToString(); // safe to remove since override of object method + s.Print(); + } + } + """, """ + using System; + public struct S { - void M2() - { - ReadOnlySpan r = [|(Span)|][1, 2, 3, 4]; + public readonly int Field; + public override string ToString() => ""; + public void Print() => Console.WriteLine(Field); + } + public class C { + S s; + + public void M() { + s.ToString(); // safe to remove since override of object method + s.Print(); } } - """, - FixedCode = """ + """); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/61922")] + public async Task IdentityStructCast8() + { + await VerifyCS.VerifyCodeFixAsync(""" using System; - using System.Collections.Generic; + public struct S { + public int Field; + public void Increment() => Field++; + public void Print() => Console.WriteLine(Field); + public int Prop => 0; + } + public class C { + S s; + + public void M() { + var v = ([|(S)|]s).Prop; // Safe because we assume non-methods don't mutate + s.Print(); + } + } + """, """ + using System; + public struct S { + public int Field; + public void Increment() => Field++; + public void Print() => Console.WriteLine(Field); + public int Prop => 0; + } + public class C { + S s; + + public void M() { + var v = s.Prop; // Safe because we assume non-methods don't mutate + s.Print(); + } + } + """); + } - public class C - { - void M2() - { - ReadOnlySpan r = [1, 2, 3, 4]; + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/61922")] + public async Task IdentityStructCast9() + { + await VerifyCS.VerifyCodeFixAsync(""" + using System; + public struct S { + public int Field; + public void Increment() => Field++; + public void Print() => Console.WriteLine(Field); + public int Prop => 0; + } + public class C { + S s; + + public void M() { + var v = [|(S)|]s; // Safe because we're not accessing a member + s.Print(); } } - """, - LanguageVersion = LanguageVersion.CSharp12, - ReferenceAssemblies = ReferenceAssemblies.Net.Net80, - }.RunAsync(); + """, """ + using System; + public struct S { + public int Field; + public void Increment() => Field++; + public void Print() => Console.WriteLine(Field); + public int Prop => 0; + } + public class C { + S s; + + public void M() { + var v = s; // Safe because we're not accessing a member + s.Print(); + } + } + """); + } } } diff --git a/src/Analyzers/CSharp/Tests/UseImplicitOrExplicitType/UseExplicitTypeTests.cs b/src/Analyzers/CSharp/Tests/UseImplicitOrExplicitType/UseExplicitTypeTests.cs index af6a76d6a3b3c..9cfd1bdbc9bf3 100644 --- a/src/Analyzers/CSharp/Tests/UseImplicitOrExplicitType/UseExplicitTypeTests.cs +++ b/src/Analyzers/CSharp/Tests/UseImplicitOrExplicitType/UseExplicitTypeTests.cs @@ -77,7 +77,7 @@ private OptionsCollection ExplicitTypeSilentEnforcement() #region Error Cases - [WpfFact] + [Fact] public async Task NotOnFieldDeclaration() { await TestMissingInRegularAndScriptAsync( @@ -91,7 +91,7 @@ class Program """, new TestParameters(options: ExplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnFieldLikeEvents() { await TestMissingInRegularAndScriptAsync( @@ -105,7 +105,7 @@ class Program """, new TestParameters(options: ExplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task OnAnonymousMethodExpression() { var before = @@ -141,7 +141,7 @@ void Method() await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact] + [Fact] public async Task OnLambdaExpression() { var before = @@ -173,7 +173,7 @@ void Method() await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact] + [Fact] public async Task NotOnDeclarationWithMultipleDeclarators() { await TestMissingInRegularAndScriptAsync( @@ -190,7 +190,7 @@ void Method() """, new TestParameters(options: ExplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnDeclarationWithoutInitializer() { await TestMissingInRegularAndScriptAsync( @@ -207,7 +207,7 @@ void Method() """, new TestParameters(options: ExplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotDuringConflicts() { await TestMissingInRegularAndScriptAsync( @@ -228,7 +228,7 @@ class var """, new TestParameters(options: ExplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotIfAlreadyExplicitlyTyped() { await TestMissingInRegularAndScriptAsync( @@ -245,7 +245,7 @@ void Method() """, new TestParameters(options: ExplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/27221")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/27221")] public async Task NotIfRefTypeAlreadyExplicitlyTyped() { await TestMissingInRegularAndScriptAsync( @@ -263,7 +263,7 @@ void Method() """, new TestParameters(options: ExplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnRHS() { await TestMissingInRegularAndScriptAsync( @@ -284,7 +284,7 @@ class var """); } - [WpfFact] + [Fact] public async Task NotOnErrorSymbol() { await TestMissingInRegularAndScriptAsync( @@ -302,7 +302,7 @@ void Method() } [WorkItem("https://github.com/dotnet/roslyn/issues/29718")] - [WpfFact] + [Fact] public async Task NotOnErrorConvertedType_ForEachVariableStatement() { await TestMissingInRegularAndScriptAsync( @@ -325,7 +325,7 @@ void M() } [WorkItem("https://github.com/dotnet/roslyn/issues/29718")] - [WpfFact] + [Fact] public async Task NotOnErrorConvertedType_AssignmentExpressionStatement() { await TestMissingInRegularAndScriptAsync( @@ -347,7 +347,7 @@ void M(C c) #endregion - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23907")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23907")] public async Task InArrayType() { var before = """ @@ -374,7 +374,7 @@ void Method() await TestMissingInRegularAndScriptAsync(before, new TestParameters(options: ExplicitTypeExceptWhereApparent())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23907")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23907")] public async Task InArrayTypeWithIntrinsicType() { var before = """ @@ -400,7 +400,7 @@ void Method() await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); // preference for builtin types dominates } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23907")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23907")] public async Task InNullableIntrinsicType() { var before = """ @@ -427,7 +427,7 @@ void Method(int? x) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/42986")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/42986")] public async Task InNativeIntIntrinsicType() { var before = """ @@ -454,7 +454,7 @@ void Method(nint x) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/42986")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/42986")] public async Task InNativeUnsignedIntIntrinsicType() { var before = """ @@ -481,7 +481,7 @@ void Method(nuint x) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/27221")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/27221")] public async Task WithRefIntrinsicType() { var before = """ @@ -510,7 +510,7 @@ void Method() await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/27221")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/27221")] public async Task WithRefIntrinsicTypeInForeach() { var before = """ @@ -545,7 +545,7 @@ void M() await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23907")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23907")] public async Task InArrayOfNullableIntrinsicType() { var before = """ @@ -572,7 +572,7 @@ void Method(int?[] x) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23907")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23907")] public async Task InNullableCustomType() { var before = """ @@ -599,7 +599,7 @@ void Method(Program? x) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] public async Task NullableType() { var before = """ @@ -630,7 +630,7 @@ void Method(Program x) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] public async Task ObliviousType() { var before = """ @@ -663,7 +663,7 @@ void Method(Program x) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] public async Task NotNullableType() { var before = """ @@ -694,7 +694,7 @@ void Method(Program x) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] public async Task NullableType_OutVar() { var before = """ @@ -725,7 +725,7 @@ void Method(out Program? x) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] public async Task NotNullableType_OutVar() { var before = """ @@ -756,7 +756,7 @@ void Method(out Program x) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] public async Task ObliviousType_OutVar() { var before = """ @@ -785,7 +785,7 @@ void Method(out Program x) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact(Skip = "https://github.com/dotnet/roslyn/issues/40925")] + [Fact(Skip = "https://github.com/dotnet/roslyn/issues/40925")] [WorkItem("https://github.com/dotnet/roslyn/issues/40477")] [WorkItem("https://github.com/dotnet/roslyn/issues/40925")] public async Task NullableTypeAndNotNullableType_VarDeconstruction() @@ -818,7 +818,7 @@ void Method(Program? x, Program2 x2) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] public async Task ObliviousType_VarDeconstruction() { var before = """ @@ -851,7 +851,7 @@ void Method(Program x, Program2 x2) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] public async Task ObliviousType_Deconstruction() { var before = """ @@ -882,7 +882,7 @@ void Method(Program x) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] public async Task NotNullableType_Deconstruction() { var before = """ @@ -911,7 +911,7 @@ void Method(Program x) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] public async Task NullableType_Deconstruction() { var before = """ @@ -940,7 +940,7 @@ void Method(Program? x) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] public async Task ObliviousType_Foreach() { var before = """ @@ -975,7 +975,7 @@ void Method(System.Collections.Generic.IEnumerable x) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] public async Task NotNullableType_Foreach() { var before = """ @@ -1008,7 +1008,7 @@ void Method(System.Collections.Generic.IEnumerable x) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] public async Task NullableType_Foreach() { var before = """ @@ -1041,7 +1041,7 @@ void Method(System.Collections.Generic.IEnumerable x) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact(Skip = "https://github.com/dotnet/roslyn/issues/37491")] + [Fact(Skip = "https://github.com/dotnet/roslyn/issues/37491")] [WorkItem("https://github.com/dotnet/roslyn/issues/40477")] public async Task NotNullableType_ForeachVarDeconstruction() { @@ -1078,7 +1078,7 @@ void Method(System.Collections.Generic.IEnumerable<(Program, Program)> x) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40477")] public async Task NotNullableType_ForeachDeconstruction() { var before = """ @@ -1111,7 +1111,7 @@ void Method(System.Collections.Generic.IEnumerable<(Program, Program)> x) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23907")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23907")] public async Task InPointerTypeWithIntrinsicType() { var before = """ @@ -1138,7 +1138,7 @@ void Method(int* y) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); // preference for builtin types dominates } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23907")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23907")] public async Task InPointerTypeWithCustomType() { var before = """ @@ -1165,7 +1165,7 @@ void Method(Program* y) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23893")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23893")] public async Task InOutParameter() { var before = """ @@ -1191,7 +1191,7 @@ void Method(out int x) await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact] + [Fact] public async Task NotOnDynamic() { await TestMissingInRegularAndScriptAsync( @@ -1208,7 +1208,7 @@ void Method() """, new TestParameters(options: ExplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnForEachVarWithAnonymousType() { await TestMissingInRegularAndScriptAsync( @@ -1231,7 +1231,7 @@ void Method() """, new TestParameters(options: ExplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23752")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23752")] public async Task OnDeconstructionVarParens() { await TestInRegularAndScriptAsync( @@ -1258,7 +1258,7 @@ void M() """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task OnDeconstructionVar() { await TestInRegularAndScriptAsync( @@ -1285,7 +1285,7 @@ void M() """, options: ExplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23752")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23752")] public async Task OnNestedDeconstructionVar() { await TestInRegularAndScriptAsync( @@ -1312,7 +1312,7 @@ void M() """, options: ExplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23752")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23752")] public async Task OnBadlyFormattedNestedDeconstructionVar() { await TestInRegularAndScriptAsync( @@ -1339,7 +1339,7 @@ void M() """, options: ExplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23752")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23752")] public async Task OnForeachNestedDeconstructionVar() { await TestInRegularAndScriptAsync( @@ -1366,7 +1366,7 @@ void M() """, options: ExplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23752")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23752")] public async Task OnNestedDeconstructionVarWithTrivia() { await TestInRegularAndScriptAsync( @@ -1393,7 +1393,7 @@ void M() """, options: ExplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23752")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23752")] public async Task OnDeconstructionVarWithDiscard() { await TestInRegularAndScriptAsync( @@ -1420,7 +1420,7 @@ void M() """, options: ExplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23752")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23752")] public async Task OnDeconstructionVarWithErrorType() { await TestInRegularAndScriptAsync( @@ -1447,7 +1447,7 @@ void M() """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task OnForEachVarWithExplicitType() { await TestInRegularAndScriptAsync( @@ -1487,7 +1487,7 @@ void Method() """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task NotOnAnonymousType() { await TestMissingInRegularAndScriptAsync( @@ -1504,7 +1504,7 @@ void Method() """, new TestParameters(options: ExplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnArrayOfAnonymousType() { await TestMissingInRegularAndScriptAsync( @@ -1521,7 +1521,7 @@ void Method() """, new TestParameters(options: ExplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnEnumerableOfAnonymousTypeFromAQueryExpression() { await TestMissingInRegularAndScriptAsync( @@ -1548,7 +1548,7 @@ class Product """); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeOnLocalWithIntrinsicTypeString() { await TestInRegularAndScriptAsync( @@ -1576,7 +1576,7 @@ static void M() """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeOnIntrinsicType() { await TestInRegularAndScriptAsync( @@ -1604,7 +1604,7 @@ static void M() """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeOnFrameworkType() { await TestInRegularAndScriptAsync( @@ -1632,7 +1632,7 @@ static void M() """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeOnUserDefinedType() { await TestInRegularAndScriptAsync( @@ -1660,7 +1660,7 @@ void M() """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeOnGenericType() { await TestInRegularAndScriptAsync( @@ -1688,7 +1688,7 @@ static void M() """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeOnSingleDimensionalArrayTypeWithNewOperator() { await TestInRegularAndScriptAsync( @@ -1716,7 +1716,7 @@ static void M() """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeOnSingleDimensionalArrayTypeWithNewOperator2() { await TestInRegularAndScriptAsync( @@ -1744,7 +1744,7 @@ static void M() """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeOnSingleDimensionalJaggedArrayType() { await TestInRegularAndScriptAsync( @@ -1778,7 +1778,7 @@ static void M() """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeOnDeclarationWithObjectInitializer() { await TestInRegularAndScriptAsync( @@ -1816,7 +1816,7 @@ private class Customer """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeOnDeclarationWithCollectionInitializer() { await TestInRegularAndScriptAsync( @@ -1846,7 +1846,7 @@ static void M() """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeOnDeclarationWithCollectionAndObjectInitializers() { await TestInRegularAndScriptAsync( @@ -1892,7 +1892,7 @@ private class Customer """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeOnForStatement() { await TestInRegularAndScriptAsync( @@ -1924,7 +1924,7 @@ static void M() """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeOnForeachStatement() { await TestInRegularAndScriptAsync( @@ -1960,7 +1960,7 @@ static void M() """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeOnQueryExpression() { await TestInRegularAndScriptAsync( @@ -2010,7 +2010,7 @@ private class Customer """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeInUsingStatement() { await TestInRegularAndScriptAsync( @@ -2058,7 +2058,7 @@ public void Dispose() """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeOnInterpolatedString() { await TestInRegularAndScriptAsync( @@ -2086,7 +2086,7 @@ void Method() """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeOnExplicitConversion() { await TestInRegularAndScriptAsync( @@ -2116,7 +2116,7 @@ static void M() """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeOnConditionalAccessExpression() { await TestInRegularAndScriptAsync( @@ -2156,7 +2156,7 @@ C Test() """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeInCheckedExpression() { await TestInRegularAndScriptAsync( @@ -2186,7 +2186,7 @@ static void M() """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeInAwaitExpression() { await TestInRegularAndScriptAsync( @@ -2226,7 +2226,7 @@ private async Task ReadTextAsync(string filePath) """, options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeInBuiltInNumericType() { await TestInRegularAndScriptAsync( @@ -2254,7 +2254,7 @@ public void ProcessRead() """, options: ExplicitTypeForBuiltInTypesOnly()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeInBuiltInCharType() { await TestInRegularAndScriptAsync( @@ -2286,7 +2286,7 @@ public void ProcessRead() """, options: ExplicitTypeForBuiltInTypesOnly()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeInBuiltInType_string() { // though string isn't an intrinsic type per the compiler @@ -2316,7 +2316,7 @@ public void ProcessRead() """, options: ExplicitTypeForBuiltInTypesOnly()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeInBuiltInType_object() { // object isn't an intrinsic type per the compiler @@ -2348,7 +2348,7 @@ public void ProcessRead() """, options: ExplicitTypeForBuiltInTypesOnly()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeNotificationLevelSilent() { var source = @@ -2368,7 +2368,7 @@ await TestDiagnosticInfoAsync(source, diagnosticSeverity: DiagnosticSeverity.Hidden); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeNotificationLevelInfo() { var source = @@ -2388,7 +2388,7 @@ await TestDiagnosticInfoAsync(source, diagnosticSeverity: DiagnosticSeverity.Info); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23907")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23907")] public async Task SuggestExplicitTypeNotificationLevelWarning() { var source = @@ -2408,7 +2408,7 @@ await TestDiagnosticInfoAsync(source, diagnosticSeverity: DiagnosticSeverity.Warning); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeNotificationLevelError() { var source = @@ -2428,7 +2428,7 @@ await TestDiagnosticInfoAsync(source, diagnosticSeverity: DiagnosticSeverity.Error); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeOnLocalWithIntrinsicTypeTuple() { await TestInRegularAndScriptAsync( @@ -2453,7 +2453,7 @@ static void M() options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeOnLocalWithIntrinsicTypeTupleWithNames() { await TestInRegularAndScriptAsync( @@ -2478,7 +2478,7 @@ static void M() options: ExplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestExplicitTypeOnLocalWithIntrinsicTypeTupleWithOneName() { await TestInRegularAndScriptAsync( @@ -2503,7 +2503,7 @@ static void M() options: ExplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/20437")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20437")] public async Task SuggestExplicitTypeOnDeclarationExpressionSyntax() { await TestInRegularAndScriptAsync( @@ -2532,7 +2532,7 @@ static void M() options: ExplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] public async Task ExplicitTypeOnPredefinedTypesByTheirMetadataNames1() { await TestMissingInRegularAndScriptAsync( @@ -2549,7 +2549,7 @@ void Method() """, new TestParameters(options: ExplicitTypeForBuiltInTypesOnly())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] public async Task ExplicitTypeOnPredefinedTypesByTheirMetadataNames2() { await TestMissingInRegularAndScriptAsync( @@ -2568,7 +2568,7 @@ void Main() """, new TestParameters(options: ExplicitTypeForBuiltInTypesOnly())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] public async Task ExplicitTypeOnPredefinedTypesByTheirMetadataNames3() { await TestMissingInRegularAndScriptAsync( @@ -2585,7 +2585,7 @@ void Main() """, new TestParameters(options: ExplicitTypeForBuiltInTypesOnly())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] public async Task ExplicitTypeOnPredefinedTypesByTheirMetadataNames4() { await TestMissingInRegularAndScriptAsync( @@ -2606,7 +2606,7 @@ void Main() """, new TestParameters(options: ExplicitTypeForBuiltInTypesOnly())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] public async Task ExplicitTypeOnPredefinedTypesByTheirMetadataNames5() { await TestMissingInRegularAndScriptAsync( @@ -2624,7 +2624,7 @@ void Main() """, new TestParameters(options: ExplicitTypeForBuiltInTypesOnly())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] public async Task ExplicitTypeOnPredefinedTypesByTheirMetadataNames6() { await TestMissingInRegularAndScriptAsync( @@ -2642,7 +2642,7 @@ void Main() """, new TestParameters(options: ExplicitTypeForBuiltInTypesOnly())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] public async Task ExplicitTypeOnPredefinedTypesByTheirMetadataNames7() { await TestMissingInRegularAndScriptAsync( @@ -2660,7 +2660,7 @@ void Main() """, new TestParameters(options: ExplicitTypeForBuiltInTypesOnly())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] public async Task ExplicitTypeOnPredefinedTypesByTheirMetadataNames8() { await TestMissingInRegularAndScriptAsync( @@ -2683,7 +2683,7 @@ private async Task ReadTextAsync(string filePath) """, new TestParameters(options: ExplicitTypeForBuiltInTypesOnly())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] public async Task ExplicitTypeOnPredefinedTypesByTheirMetadataNames9() { await TestMissingInRegularAndScriptAsync( @@ -2701,7 +2701,7 @@ void Main() """, new TestParameters(options: ExplicitTypeForBuiltInTypesOnly())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] public async Task ExplicitTypeOnPredefinedTypesByTheirMetadataNames10() { await TestMissingInRegularAndScriptAsync( @@ -2720,7 +2720,7 @@ void Main() """, new TestParameters(options: ExplicitTypeForBuiltInTypesOnly())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20244")] public async Task ExplicitTypeOnPredefinedTypesByTheirMetadataNames11() { await TestMissingInRegularAndScriptAsync( @@ -2738,7 +2738,7 @@ void Main() """, new TestParameters(options: ExplicitTypeForBuiltInTypesOnly())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/26923")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26923")] public async Task NoSuggestionOnForeachCollectionExpression() { await TestMissingInRegularAndScriptAsync( @@ -2759,7 +2759,7 @@ void Method(List var) """, new TestParameters(options: ExplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnConstVar() { // This error case is handled by a separate code fix (UseExplicitTypeForConst). @@ -2775,7 +2775,7 @@ void M() """, new TestParameters(options: ExplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23907")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23907")] public async Task WithNormalFuncSynthesizedLambdaType() { var before = """ @@ -2802,7 +2802,7 @@ void Method() await TestInRegularAndScriptAsync(before, after, options: ExplicitTypeExceptWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23907")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23907")] public async Task WithAnonymousSynthesizedLambdaType() { var before = """ diff --git a/src/Analyzers/CSharp/Tests/UseImplicitOrExplicitType/UseImplicitTypeTests.cs b/src/Analyzers/CSharp/Tests/UseImplicitOrExplicitType/UseImplicitTypeTests.cs index b787b49b4bbc7..9fd211d9bad61 100644 --- a/src/Analyzers/CSharp/Tests/UseImplicitOrExplicitType/UseImplicitTypeTests.cs +++ b/src/Analyzers/CSharp/Tests/UseImplicitOrExplicitType/UseImplicitTypeTests.cs @@ -84,7 +84,7 @@ private OptionsCollection ImplicitTypeSilentEnforcement() { CSharpCodeStyleOptions.VarForBuiltInTypes, onWithSilent }, }; - [WpfFact] + [Fact] public async Task NotOnFieldDeclaration() { await TestMissingInRegularAndScriptAsync( @@ -98,7 +98,7 @@ class Program """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnFieldLikeEvents() { await TestMissingInRegularAndScriptAsync( @@ -112,7 +112,7 @@ class Program """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnConstants() { await TestMissingInRegularAndScriptAsync( @@ -129,7 +129,7 @@ void Method() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnNullLiteral() { await TestMissingInRegularAndScriptAsync( @@ -146,7 +146,7 @@ void Method() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/27221")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/27221")] public async Task NotOnRefVar() { await TestMissingInRegularAndScriptAsync(""" @@ -161,7 +161,7 @@ void Method() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnDynamic() { await TestMissingInRegularAndScriptAsync( @@ -178,7 +178,7 @@ void Method() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnAnonymousMethodExpression() { await TestMissingInRegularAndScriptAsync( @@ -197,7 +197,7 @@ void Method() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnLambdaExpression() { await TestMissingInRegularAndScriptAsync( @@ -214,7 +214,7 @@ void Method() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnMethodGroup() { await TestMissingInRegularAndScriptAsync( @@ -231,7 +231,7 @@ void Method() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnDeclarationWithMultipleDeclarators() { await TestMissingInRegularAndScriptAsync( @@ -248,7 +248,7 @@ void Method() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnDeclarationWithoutInitializer() { await TestMissingInRegularAndScriptAsync( @@ -265,7 +265,7 @@ void Method() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnIFormattable() { await TestMissingInRegularAndScriptAsync( @@ -282,7 +282,7 @@ void Method() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnFormattableString() { await TestMissingInRegularAndScriptAsync( @@ -299,7 +299,7 @@ void Method() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotInCatchDeclaration() { await TestMissingInRegularAndScriptAsync( @@ -322,7 +322,7 @@ void Method() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotDuringConflicts() { await TestMissingInRegularAndScriptAsync( @@ -343,7 +343,7 @@ class var """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotIfAlreadyImplicitlyTyped() { await TestMissingInRegularAndScriptAsync( @@ -360,7 +360,7 @@ void Method() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnImplicitConversion() { await TestMissingInRegularAndScriptAsync( @@ -378,7 +378,7 @@ void Method() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnBoxingImplicitConversion() { await TestMissingInRegularAndScriptAsync( @@ -396,7 +396,7 @@ void Method() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnRHS() { await TestMissingInRegularAndScriptAsync( @@ -413,7 +413,7 @@ void M() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnVariablesUsedInInitalizerExpression() { await TestMissingInRegularAndScriptAsync( @@ -430,7 +430,7 @@ void M() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/26894")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26894")] public async Task NotOnVariablesOfEnumTypeNamedAsEnumTypeUsedInInitalizerExpressionAtFirstPosition() { await TestMissingInRegularAndScriptAsync( @@ -449,7 +449,7 @@ void M() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/26894")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26894")] public async Task NotOnVariablesNamedAsTypeUsedInInitalizerExpressionContainingTypeNameAtFirstPositionOfMemberAccess() { await TestMissingInRegularAndScriptAsync( @@ -471,7 +471,7 @@ void M() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/26894")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26894")] public async Task SuggestOnVariablesUsedInInitalizerExpressionAsInnerPartsOfQualifiedNameStartedWithGlobal() { await TestAsync( @@ -499,7 +499,7 @@ void M() """, CSharpParseOptions.Default, options: ImplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/26894")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26894")] public async Task SuggestOnVariablesUsedInInitalizerExpressionAsInnerPartsOfQualifiedName() { await TestInRegularAndScriptAsync( @@ -543,7 +543,7 @@ void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/26894")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26894")] public async Task SuggestOnVariablesUsedInInitalizerExpressionAsLastPartOfQualifiedName() { await TestInRegularAndScriptAsync( @@ -585,7 +585,7 @@ void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task NotOnAssignmentToInterfaceType() { await TestMissingInRegularAndScriptAsync( @@ -610,7 +610,7 @@ interface IInterface """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task NotOnArrayInitializerWithoutNewKeyword() { await TestMissingInRegularAndScriptAsync( @@ -632,7 +632,7 @@ static void M() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task SuggestVarOnLocalWithIntrinsicTypeString() { await TestInRegularAndScriptAsync( @@ -660,7 +660,7 @@ static void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestVarOnIntrinsicType() { await TestInRegularAndScriptAsync( @@ -688,7 +688,7 @@ static void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/27221")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/27221")] public async Task SuggestVarOnRefIntrinsicType() { await TestInRegularAndScriptAsync( @@ -718,7 +718,7 @@ static void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/27221")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/27221")] public async Task WithRefIntrinsicTypeInForeach() { var before = """ @@ -750,7 +750,7 @@ void M() await TestInRegularAndScriptAsync(before, after, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestVarOnFrameworkType() { await TestInRegularAndScriptAsync( @@ -778,7 +778,7 @@ static void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestVarOnUserDefinedType() { await TestInRegularAndScriptAsync( @@ -806,7 +806,7 @@ void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestVarOnGenericType() { await TestInRegularAndScriptAsync( @@ -834,7 +834,7 @@ static void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestVarOnSeeminglyConflictingType() { await TestInRegularAndScriptAsync( @@ -862,7 +862,7 @@ void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestVarOnSingleDimensionalArrayTypeWithNewOperator() { await TestInRegularAndScriptAsync( @@ -890,7 +890,7 @@ static void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestVarOnSingleDimensionalArrayTypeWithNewOperator2() { await TestInRegularAndScriptAsync( @@ -918,7 +918,7 @@ static void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestVarOnSingleDimensionalJaggedArrayType() { await TestInRegularAndScriptAsync( @@ -952,7 +952,7 @@ static void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestVarOnDeclarationWithObjectInitializer() { await TestInRegularAndScriptAsync( @@ -990,7 +990,7 @@ private class Customer """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestVarOnDeclarationWithCollectionInitializer() { await TestInRegularAndScriptAsync( @@ -1020,7 +1020,7 @@ static void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestVarOnDeclarationWithCollectionAndObjectInitializers() { await TestInRegularAndScriptAsync( @@ -1066,7 +1066,7 @@ private class Customer """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestVarOnForStatement() { await TestInRegularAndScriptAsync( @@ -1098,7 +1098,7 @@ static void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestVarOnForeachStatement() { await TestInRegularAndScriptAsync( @@ -1134,7 +1134,7 @@ static void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestVarOnQueryExpression() { await TestInRegularAndScriptAsync( @@ -1184,7 +1184,7 @@ private class Customer """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestVarInUsingStatement() { await TestInRegularAndScriptAsync( @@ -1232,7 +1232,7 @@ public void Dispose() """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestVarOnExplicitConversion() { await TestInRegularAndScriptAsync( @@ -1262,7 +1262,7 @@ void Method() """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestVarInConditionalAccessExpression() { await TestInRegularAndScriptAsync( @@ -1302,7 +1302,7 @@ C Test() """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestVarInCheckedExpression() { await TestInRegularAndScriptAsync( @@ -1332,7 +1332,7 @@ static void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestVarInUnCheckedExpression() { await TestInRegularAndScriptAsync( @@ -1362,7 +1362,7 @@ static void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestVarInAwaitExpression() { await TestInRegularAndScriptAsync( @@ -1402,7 +1402,7 @@ private async Task ReadTextAsync(string filePath) """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task SuggestVarInParenthesizedExpression() { await TestInRegularAndScriptAsync( @@ -1430,7 +1430,7 @@ public void ProcessRead() """, options: ImplicitTypeEverywhere()); } - [WpfFact] + [Fact] public async Task DoNotSuggestVarOnBuiltInType_Literal_WithOption() { await TestMissingInRegularAndScriptAsync( @@ -1447,7 +1447,7 @@ static void M() """, new TestParameters(options: ImplicitTypeButKeepIntrinsics())); } - [WpfFact] + [Fact] public async Task DoNotSuggestVarOnBuiltInType_WithOption() { await TestMissingInRegularAndScriptAsync( @@ -1466,7 +1466,7 @@ static void M() """, new TestParameters(options: ImplicitTypeButKeepIntrinsics())); } - [WpfFact] + [Fact] public async Task DoNotSuggestVarOnFrameworkTypeEquivalentToBuiltInType() { await TestMissingInRegularAndScriptAsync( @@ -1485,7 +1485,7 @@ static void M() """, new TestParameters(options: ImplicitTypeButKeepIntrinsics())); } - [WpfFact] + [Fact] public async Task SuggestVarWhereTypeIsEvident_DefaultExpression() { await TestInRegularAndScriptAsync( @@ -1513,7 +1513,7 @@ public void Process() """, options: ImplicitTypeWhereApparent()); } - [WpfFact] + [Fact] public async Task SuggestVarWhereTypeIsEvident_Literals() { await TestInRegularAndScriptAsync( @@ -1541,7 +1541,7 @@ public void Process() """, options: ImplicitTypeWhereApparentAndForIntrinsics()); } - [WpfFact] + [Fact] public async Task DoNotSuggestVarWhereTypeIsEvident_Literals() { await TestMissingInRegularAndScriptAsync( @@ -1558,7 +1558,7 @@ public void Process() """, new TestParameters(options: ImplicitTypeWhereApparent())); } - [WpfFact] + [Fact] public async Task SuggestVarWhereTypeIsEvident_ObjectCreationExpression() { await TestInRegularAndScriptAsync( @@ -1586,7 +1586,7 @@ public void Process() """, options: ImplicitTypeWhereApparent()); } - [WpfFact] + [Fact] public async Task SuggestVarWhereTypeIsEvident_CastExpression() { await TestInRegularAndScriptAsync( @@ -1616,7 +1616,7 @@ public void Process() """, options: ImplicitTypeWhereApparent()); } - [WpfFact] + [Fact] public async Task DoNotSuggestVar_BuiltInTypesRulePrecedesOverTypeIsApparentRule1() { await TestMissingInRegularAndScriptAsync( @@ -1634,7 +1634,7 @@ public void Process() """, new TestParameters(options: ImplicitTypeWhereApparent())); } - [WpfFact] + [Fact] public async Task DoNotSuggestVar_BuiltInTypesRulePrecedesOverTypeIsApparentRule2() { await TestMissingInRegularAndScriptAsync( @@ -1652,7 +1652,7 @@ public void Process() """, new TestParameters(options: ImplicitTypeWhereApparent())); } - [WpfFact] + [Fact] public async Task DoNotSuggestVarWhereTypeIsEvident_IsExpression() { await TestMissingInRegularAndScriptAsync( @@ -1678,7 +1678,7 @@ interface IInterface """, new TestParameters(options: ImplicitTypeWhereApparent())); } - [WpfFact] + [Fact] public async Task SuggestVarWhereTypeIsEvident_AsExpression() { await TestInRegularAndScriptAsync( @@ -1724,7 +1724,7 @@ interface IInterface """, options: ImplicitTypeWhereApparent()); } - [WpfFact] + [Fact] public async Task SuggestVarWhereTypeIsEvident_ConversionHelpers() { await TestInRegularAndScriptAsync( @@ -1752,7 +1752,7 @@ public void Process() """, options: ImplicitTypeWhereApparent()); } - [WpfFact] + [Fact] public async Task SuggestVarWhereTypeIsEvident_CreationHelpers() { await TestInRegularAndScriptAsync( @@ -1786,7 +1786,7 @@ class XElement """, options: ImplicitTypeWhereApparent()); } - [WpfFact] + [Fact] public async Task SuggestVarWhereTypeIsEvident_CreationHelpersWithInferredTypeArguments() { await TestInRegularAndScriptAsync( @@ -1814,7 +1814,7 @@ public void Process() """, options: ImplicitTypeWhereApparent()); } - [WpfFact] + [Fact] public async Task SuggestVarWhereTypeIsEvident_ConvertToType() { await TestInRegularAndScriptAsync( @@ -1844,7 +1844,7 @@ public void Process() """, options: ImplicitTypeWhereApparent()); } - [WpfFact] + [Fact] public async Task SuggestVarWhereTypeIsEvident_IConvertibleToType() { await TestInRegularAndScriptAsync( @@ -1876,7 +1876,7 @@ public void Process() """, options: ImplicitTypeWhereApparent()); } - [WpfFact] + [Fact] public async Task SuggestVarNotificationLevelSilent() { var source = @@ -1896,7 +1896,7 @@ await TestDiagnosticInfoAsync(source, diagnosticSeverity: DiagnosticSeverity.Hidden); } - [WpfFact] + [Fact] public async Task SuggestVarNotificationLevelInfo() { var source = @@ -1916,7 +1916,7 @@ await TestDiagnosticInfoAsync(source, diagnosticSeverity: DiagnosticSeverity.Info); } - [WpfFact] + [Fact] public async Task SuggestVarNotificationLevelWarning() { var source = @@ -1936,7 +1936,7 @@ await TestDiagnosticInfoAsync(source, diagnosticSeverity: DiagnosticSeverity.Warning); } - [WpfFact] + [Fact] public async Task SuggestVarNotificationLevelError() { var source = @@ -1956,7 +1956,7 @@ await TestDiagnosticInfoAsync(source, diagnosticSeverity: DiagnosticSeverity.Error); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23893")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23893")] public async Task SuggestVarOnLocalWithIntrinsicArrayType() { var before = @"class C { static void M() { [|int[]|] s = new int[0]; } }"; @@ -1968,7 +1968,7 @@ public async Task SuggestVarOnLocalWithIntrinsicArrayType() await TestMissingInRegularAndScriptAsync(before, new TestParameters(options: ImplicitTypeWhereApparent())); // Preference of intrinsic types dominates } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23893")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23893")] public async Task SuggestVarOnLocalWithCustomArrayType() { var before = @"class C { static void M() { [|C[]|] s = new C[0]; } }"; @@ -1980,7 +1980,7 @@ public async Task SuggestVarOnLocalWithCustomArrayType() await TestInRegularAndScriptAsync(before, after, options: ImplicitTypeWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23893")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23893")] public async Task SuggestVarOnLocalWithNonApparentCustomArrayType() { var before = @"class C { static void M() { [|C[]|] s = new[] { new C() }; } }"; @@ -2010,7 +2010,7 @@ public ValueTuple(T1 item1, T2 item2) { } } """; - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/11094")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11094")] public async Task SuggestVarOnLocalWithIntrinsicTypeTuple() { var before = @"class C { static void M() { [|(int a, string)|] s = (a: 1, ""hello""); } }"; @@ -2021,7 +2021,7 @@ public async Task SuggestVarOnLocalWithIntrinsicTypeTuple() await TestMissingInRegularAndScriptAsync(before, new TestParameters(options: ImplicitTypeWhereApparent())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/11094")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11094")] public async Task SuggestVarOnLocalWithNonApparentTupleType() { var before = @"class C { static void M(C c) { [|(int a, C b)|] s = (a: 1, b: c); } }"; @@ -2032,7 +2032,7 @@ public async Task SuggestVarOnLocalWithNonApparentTupleType() await TestMissingInRegularAndScriptAsync(before, new TestParameters(options: ImplicitTypeWhereApparent())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/11154")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11154")] public async Task ValueTupleCreate() { await TestInRegularAndScriptAsync( @@ -2061,7 +2061,7 @@ static void M() options: ImplicitTypeWhereApparent()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/11095")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/11095")] public async Task ValueTupleCreate_2() { await TestInRegularAndScriptAsync( @@ -2090,7 +2090,7 @@ static void M() options: ImplicitTypeWhereApparent()); } - [WpfFact] + [Fact] public async Task TupleWithDifferentNames() { await TestMissingInRegularAndScriptAsync( @@ -2106,7 +2106,7 @@ static void M() new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/14052")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/14052")] public async Task DoNotOfferOnForEachConversionIfItChangesSemantics() { await TestMissingInRegularAndScriptAsync( @@ -2143,7 +2143,7 @@ static void M() new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/14052")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/14052")] public async Task OfferOnForEachConversionIfItDoesNotChangesSemantics() { await TestInRegularAndScriptAsync( @@ -2209,7 +2209,7 @@ static void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/20437")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/20437")] public async Task SuggestVarOnDeclarationExpressionSyntax() { await TestInRegularAndScriptAsync( @@ -2238,7 +2238,7 @@ static void M() options: ImplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23893")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23893")] public async Task DoNotSuggestVarOnDeclarationExpressionSyntaxWithIntrinsicType() { var before = @@ -2254,7 +2254,7 @@ static void M(out int x) await TestMissingInRegularAndScriptAsync(before, new TestParameters(options: ImplicitTypeButKeepIntrinsics())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/22768")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22768")] public async Task DoNotSuggestVarOnStackAllocExpressions_SpanType() { await TestMissingInRegularAndScriptAsync(""" @@ -2276,7 +2276,7 @@ static void M() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/22768")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22768")] public async Task DoNotSuggestVarOnStackAllocExpressions_SpanType_NestedConditional() { await TestMissingInRegularAndScriptAsync(""" @@ -2298,7 +2298,7 @@ static void M(bool choice) """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/22768")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22768")] public async Task DoNotSuggestVarOnStackAllocExpressions_SpanType_NestedCast() { await TestMissingInRegularAndScriptAsync(""" @@ -2320,7 +2320,7 @@ static void M() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/22768")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22768")] public async Task SuggestVarOnLambdasWithNestedStackAllocs() { await TestInRegularAndScriptAsync(""" @@ -2352,7 +2352,7 @@ unsafe static void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/22768")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22768")] public async Task SuggestVarOnAnonymousMethodsWithNestedStackAllocs() { await TestInRegularAndScriptAsync(""" @@ -2384,7 +2384,7 @@ unsafe static void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/22768")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22768")] public async Task SuggestVarOnStackAllocsNestedInLambdas() { await TestInRegularAndScriptAsync(""" @@ -2416,7 +2416,7 @@ unsafe static void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/22768")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22768")] public async Task SuggestVarOnStackAllocsNestedInAnonymousMethods() { await TestInRegularAndScriptAsync(""" @@ -2448,7 +2448,7 @@ unsafe static void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/22768")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/22768")] public async Task SuggestVarOnStackAllocsInOuterMethodScope() { await TestInRegularAndScriptAsync(""" @@ -2470,7 +2470,7 @@ unsafe static void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23116")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23116")] public async Task DoSuggestForDeclarationExpressionIfItWouldNotChangeOverloadResolution2() { await TestInRegularAndScriptAsync(""" @@ -2500,7 +2500,7 @@ static int Main(string[] args) """, options: ImplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23116")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23116")] public async Task DoNotSuggestForDeclarationExpressionIfItWouldChangeOverloadResolution() { await TestMissingInRegularAndScriptAsync(""" @@ -2519,7 +2519,7 @@ static int Main(string[] args) """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23116")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23116")] public async Task DoNotSuggestIfChangesGenericTypeInference() { await TestMissingInRegularAndScriptAsync(""" @@ -2536,7 +2536,7 @@ static int Main(string[] args) """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23116")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23116")] public async Task SuggestIfDoesNotChangeGenericTypeInference1() { await TestInRegularAndScriptAsync(""" @@ -2564,7 +2564,7 @@ static int Main(string[] args) """, options: ImplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23116")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23116")] public async Task SuggestIfDoesNotChangeGenericTypeInference2() { await TestInRegularAndScriptAsync(""" @@ -2592,7 +2592,7 @@ static int Main(string[] args) """, options: ImplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23711")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23711")] public async Task SuggestVarForDelegateType() { await TestInRegularAndScriptAsync(""" @@ -2622,7 +2622,7 @@ static void Main(string[] args) """, options: ImplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23711")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23711")] public async Task DoNotSuggestVarForDelegateType1() { await TestMissingInRegularAndScriptAsync(""" @@ -2640,7 +2640,7 @@ static void Main(string[] args) """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23711")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23711")] public async Task DoNotSuggestVarForDelegateType2() { await TestMissingInRegularAndScriptAsync(""" @@ -2660,7 +2660,7 @@ static void Main(string[] args) """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/23711")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23711")] public async Task DoNotSuggestVarForDelegateType3() { await TestMissingInRegularAndScriptAsync(""" @@ -2678,7 +2678,7 @@ static void Main(string[] args) """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/24262")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/24262")] public async Task DoNotSuggestVarForInterfaceVariableInForeachStatement() { await TestMissingInRegularAndScriptAsync(""" @@ -2706,7 +2706,7 @@ public void TestIt() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/24262")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/24262")] public async Task DoNotSuggestVarForInterfaceVariableInDeclarationStatement() { await TestMissingInRegularAndScriptAsync(""" @@ -2730,7 +2730,7 @@ public void TestIt() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/24262")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/24262")] public async Task DoNotSuggestVarForAbstractClassVariableInForeachStatement() { await TestMissingInRegularAndScriptAsync(""" @@ -2759,7 +2759,7 @@ public void TestIt() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/24262")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/24262")] public async Task DoNotSuggestVarForAbstractClassVariableInDeclarationStatement() { await TestMissingInRegularAndScriptAsync(""" @@ -2785,7 +2785,7 @@ public void TestIt() """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task DoNoSuggestVarForRefForeachVar() { await TestMissingInRegularAndScriptAsync(""" @@ -2817,7 +2817,7 @@ public void M(Span span) """, new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/26923")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/26923")] public async Task NoSuggestionOnForeachCollectionExpression() { await TestMissingInRegularAndScriptAsync( @@ -2839,7 +2839,7 @@ static void Main(string[] args) } [WorkItem("https://github.com/dotnet/roslyn/issues/39171")] - [WpfFact] + [Fact] public async Task NoSuggestionForSwitchExpressionDifferentTypes() { await TestMissingInRegularAndScriptAsync( @@ -2866,7 +2866,7 @@ public static void Test(string name) } [WorkItem("https://github.com/dotnet/roslyn/issues/39171")] - [WpfFact] + [Fact] public async Task SuggestSwitchExpressionSameOrInheritedTypes() { await TestInRegularAndScriptAsync( @@ -2914,7 +2914,7 @@ void M() """, options: ImplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/32088")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/32088")] public async Task DoNotSuggestVarOnDeclarationExpressionWithInferredTupleNames() { await TestMissingAsync( @@ -2938,7 +2938,7 @@ static void Main(string[] args) """, parameters: new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/32088")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/32088")] public async Task DoSuggestVarOnDeclarationExpressionWithMatchingTupleNames() { await TestInRegularAndScriptAsync( @@ -2981,7 +2981,7 @@ static void Main(string[] args) options: ImplicitTypeEverywhere()); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/44507")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/44507")] public async Task DoNotSuggestVarInAmbiguousSwitchExpression() { await TestMissingAsync( @@ -3012,7 +3012,7 @@ class B : C """, parameters: new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/44507")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/44507")] public async Task DoNotSuggestVarInSwitchExpressionWithDelegateType() { await TestMissingAsync( @@ -3040,7 +3040,7 @@ private void M(object sender, EventArgs e) """, parameters: new TestParameters(options: ImplicitTypeEverywhere())); } - [WpfFact] + [Fact] public async Task DoNotSuggestVarForImplicitObjectCreation() { await TestMissingInRegularAndScriptAsync( @@ -3304,7 +3304,7 @@ bool GetNonNullString(out string s) """, options: ImplicitTypeEverywhere()); - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/41780")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41780")] public async Task SuggestOnRefType1() { await TestAsync( diff --git a/src/Analyzers/VisualBasic/Tests/RemoveUnnecessaryCast/RemoveUnnecessaryCastTests.vb b/src/Analyzers/VisualBasic/Tests/RemoveUnnecessaryCast/RemoveUnnecessaryCastTests.vb index d3d6fb730fc65..e89f351c2be6e 100644 --- a/src/Analyzers/VisualBasic/Tests/RemoveUnnecessaryCast/RemoveUnnecessaryCastTests.vb +++ b/src/Analyzers/VisualBasic/Tests/RemoveUnnecessaryCast/RemoveUnnecessaryCastTests.vb @@ -2155,7 +2155,7 @@ End Class End Function - + Public Async Function TestDoNotRemoveNecessaryCastInSelectCaseExpression() As Task ' Cast removal invokes a different user defined operator, hence the cast is necessary. @@ -2200,7 +2200,7 @@ End Namespace]]> End Function - + Public Async Function TestDoNotRemoveNecessaryCastInSelectCaseExpression2() As Task ' Cast removal invokes a different user defined operator, hence the cast is necessary. @@ -2245,7 +2245,7 @@ End Namespace]]> End Function - + Public Async Function TestDoNotRemoveNecessaryCastInSelectCaseExpression3() As Task ' Cast removal invokes a different user defined operator, hence the cast is necessary. diff --git a/src/Features/CSharpTest/CodeActions/ApplyChangesOperationTests.cs b/src/Features/CSharpTest/CodeActions/ApplyChangesOperationTests.cs index db04b0b767f63..c2b50147ee465 100644 --- a/src/Features/CSharpTest/CodeActions/ApplyChangesOperationTests.cs +++ b/src/Features/CSharpTest/CodeActions/ApplyChangesOperationTests.cs @@ -54,7 +54,7 @@ public TestCodeAction(Solution changedSolution) } } - [WpfFact, WorkItem("https://devdiv.visualstudio.com/DevDiv/_queries/edit/1419139")] + [Fact, WorkItem("https://devdiv.visualstudio.com/DevDiv/_queries/edit/1419139")] public async Task TestMakeTextChangeWithInterveningEditToDifferentFile() { // This should succeed as the code action is trying to edit a file that is not touched by the actual @@ -86,7 +86,7 @@ class Program2 }); } - [WpfFact, WorkItem("https://devdiv.visualstudio.com/DevDiv/_queries/edit/1419139")] + [Fact, WorkItem("https://devdiv.visualstudio.com/DevDiv/_queries/edit/1419139")] public async Task TestMakeTextChangeWithInterveningRemovalToDifferentFile() { // This should succeed as the code action is trying to edit a file that is not touched by the actual @@ -118,7 +118,7 @@ class Program2 }); } - [WpfFact, WorkItem("https://devdiv.visualstudio.com/DevDiv/_queries/edit/1419139")] + [Fact, WorkItem("https://devdiv.visualstudio.com/DevDiv/_queries/edit/1419139")] public async Task TestMakeTextChangeWithInterveningEditToSameFile() { // This should fail as the code action is trying to edit a file that is was already edited by the actual @@ -150,7 +150,7 @@ class Program2 }); } - [WpfFact, WorkItem("https://devdiv.visualstudio.com/DevDiv/_queries/edit/1419139")] + [Fact, WorkItem("https://devdiv.visualstudio.com/DevDiv/_queries/edit/1419139")] public async Task TestMakeTextChangeWithInterveningRemovalOfThatFile() { // This should fail as the code action is trying to edit a file that is subsequently removed. @@ -181,7 +181,7 @@ class Program2 }); } - [WpfFact, WorkItem("https://devdiv.visualstudio.com/DevDiv/_queries/edit/1419139")] + [Fact, WorkItem("https://devdiv.visualstudio.com/DevDiv/_queries/edit/1419139")] public async Task TestMakeProjectChangeWithInterveningTextEdit() { // This should fail as we don't want to make non-text changes that may have undesirable results to the solution diff --git a/src/Features/CSharpTest/GenerateMethod/GenerateMethodTests.cs b/src/Features/CSharpTest/GenerateMethod/GenerateMethodTests.cs index d2db75fde8965..c5e1753e0f41c 100644 --- a/src/Features/CSharpTest/GenerateMethod/GenerateMethodTests.cs +++ b/src/Features/CSharpTest/GenerateMethod/GenerateMethodTests.cs @@ -1108,7 +1108,7 @@ private void Goo(int? v) """); } - [WpfFact] + [Fact] public async Task TestPointArgument() { await TestInRegularAndScriptAsync( @@ -1141,7 +1141,7 @@ private unsafe void Goo(int* p) """); } - [WpfFact] + [Fact] public async Task TestArgumentWithPointerName() { await TestInRegularAndScriptAsync( @@ -1174,7 +1174,7 @@ private unsafe void Goo(int* p) """); } - [WpfFact] + [Fact] public async Task TestArgumentWithPointTo() { await TestInRegularAndScriptAsync( @@ -1207,7 +1207,7 @@ private void Goo(int v) """); } - [WpfFact] + [Fact] public async Task TestArgumentWithAddress() { await TestInRegularAndScriptAsync( diff --git a/src/Features/CSharpTest/GenerateType/GenerateTypeTests.cs b/src/Features/CSharpTest/GenerateType/GenerateTypeTests.cs index bac72b2beb2c2..abaeb28634f8c 100644 --- a/src/Features/CSharpTest/GenerateType/GenerateTypeTests.cs +++ b/src/Features/CSharpTest/GenerateType/GenerateTypeTests.cs @@ -473,7 +473,7 @@ private class Goo index: 2); } - [WpfFact] + [Fact] public async Task TestGenerateClassFromFieldDeclarationIntoGlobalNamespace() { await TestAddDocumentInRegularAndScriptAsync( @@ -485,7 +485,7 @@ await TestAddDocumentInRegularAndScriptAsync( expectedDocumentName: "Goo.cs"); } - [WpfFact] + [Fact] public async Task TestGenerateClassFromFieldDeclarationIntoCustomNamespace() { await TestAddDocumentInRegularAndScriptAsync( @@ -1177,7 +1177,7 @@ internal class C } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/538516")] - [WpfFact] + [Fact] public async Task TestGenerateClassFromIntoNewNamespace() { await TestAddDocumentInRegularAndScriptAsync( @@ -3357,7 +3357,7 @@ internal class @int } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539535")] - [WpfFact] + [Fact] public async Task TestGenerateIntoNewFile() { await TestAddDocumentInRegularAndScriptAsync( @@ -3375,7 +3375,7 @@ public Bar() expectedDocumentName: "Bar.cs"); } - [WpfFact] + [Fact] public async Task TestGenerateIntoNewFileWithUsings1() { await TestAddDocumentInRegularAndScriptAsync( @@ -3398,7 +3398,7 @@ public Bar(List list) expectedDocumentName: "Bar.cs"); } - [WpfFact] + [Fact] public async Task TestGenerateIntoNewFileWithUsings2() { await TestAddDocumentInRegularAndScriptAsync( @@ -4685,7 +4685,7 @@ await TestSmartTagTextAsync( } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/543853")] - [WpfFact] + [Fact] public async Task TestAddDocumentForGlobalNamespace() { await TestAddDocumentInRegularAndScriptAsync( @@ -4858,7 +4858,7 @@ public class C } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/932602")] - [WpfFact] + [Fact] public async Task TestGenerateTypeInFolderNotDefaultNamespace_0() { var code = @" @@ -4887,7 +4887,7 @@ await TestAddDocumentInRegularAndScriptAsync(code, expectedDocumentName: "ClassB.cs"); } - [WpfFact] + [Fact] public async Task TestGenerateTypeInFolderNotDefaultNamespace_0_FileScopedNamespace() { var code = @" @@ -4918,7 +4918,7 @@ await TestAddDocumentInRegularAndScriptAsync(code, } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/932602")] - [WpfFact] + [Fact] public async Task TestGenerateTypeInFolderNotDefaultNamespace_1() { var code = @" @@ -5309,7 +5309,7 @@ public B() } [WorkItem("https://github.com/dotnet/roslyn/issues/17361")] - [WpfFact] + [Fact] public async Task TestPreserveFileBanner1() { await TestAddDocumentInRegularAndScriptAsync( @@ -5332,7 +5332,7 @@ internal class Goo } [WorkItem("https://github.com/dotnet/roslyn/issues/17361")] - [WpfFact] + [Fact] public async Task TestPreserveFileBanner2() { await TestAddDocumentInRegularAndScriptAsync( @@ -5352,7 +5352,7 @@ void Main ( ) } [WorkItem("https://github.com/dotnet/roslyn/issues/17361")] - [WpfFact] + [Fact] public async Task TestPreserveFileBanner3() { await TestAddDocumentInRegularAndScriptAsync( @@ -5383,7 +5383,7 @@ public Goo(StackOverflowException e) } [WorkItem("https://github.com/dotnet/roslyn/issues/17361")] - [WpfFact] + [Fact] public async Task TestPreserveFileBanner4() { await TestAddDocumentInRegularAndScriptAsync( diff --git a/src/Features/CSharpTest/GenerateType/GenerateTypeTests_Dialog.cs b/src/Features/CSharpTest/GenerateType/GenerateTypeTests_Dialog.cs index 25675f21490e0..22d13f75d98b4 100644 --- a/src/Features/CSharpTest/GenerateType/GenerateTypeTests_Dialog.cs +++ b/src/Features/CSharpTest/GenerateType/GenerateTypeTests_Dialog.cs @@ -727,7 +727,7 @@ public interface Goo #endregion #region SameProject_NewFile - [WpfFact] + [Fact] public async Task GenerateTypeInNewFile() { await TestWithMockedGenerateTypeDialog( @@ -763,7 +763,7 @@ public interface Goo } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/850101")] - [WpfFact] + [Fact] public async Task GenerateType_UsingsNotNeeded_InNewFile_InFolder() { await TestWithMockedGenerateTypeDialog( @@ -803,7 +803,7 @@ public interface Goo } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/850101")] - [WpfFact] + [Fact] public async Task GenerateType_UsingsNeeded_InNewFile_InFolder() { await TestWithMockedGenerateTypeDialog( @@ -846,7 +846,7 @@ void Main() } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/850101")] - [WpfFact] + [Fact] public async Task GenerateType_UsingsNotNeeded_InNewFile_InFolder_NotSimpleName() { await TestWithMockedGenerateTypeDialog( @@ -883,7 +883,7 @@ public interface Goo } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/850101")] - [WpfFact] + [Fact] public async Task GenerateType_UsingsNeeded_InNewFile_InFolder_DefaultNamespace() { await TestWithMockedGenerateTypeDialog( @@ -927,7 +927,7 @@ void Main() } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/850101")] - [WpfFact] + [Fact] public async Task GenerateType_UsingsNotNeeded_InNewFile_InFolder_DefaultNamespace() { await TestWithMockedGenerateTypeDialog( @@ -975,7 +975,7 @@ void Main() } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/850101")] - [WpfFact] + [Fact] public async Task GenerateType_UsingsNotNeeded_InNewFile_InFolder_DefaultNamespace_NotSimpleName() { await TestWithMockedGenerateTypeDialog( @@ -1025,7 +1025,7 @@ namespace A.B } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/898452")] - [WpfFact] + [Fact] public async Task GenerateType_InValidFolderNameNotMadeNamespace() { await TestWithMockedGenerateTypeDialog( @@ -1235,7 +1235,7 @@ void Main() #endregion #region SameLanguageDifferentProject_NewFile - [WpfFact] + [Fact] public async Task GenerateTypeIntoSameLanguageDifferentProjectNewFile() { await TestWithMockedGenerateTypeDialog( @@ -1274,7 +1274,7 @@ public interface Goo } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/850101")] - [WpfFact] + [Fact] public async Task GenerateTypeIntoSameLanguageDifferentProjectNewFile_Folders_Usings() { await TestWithMockedGenerateTypeDialog( @@ -1320,7 +1320,7 @@ void Main() } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/850101")] - [WpfFact] + [Fact] public async Task GenerateTypeIntoSameLanguageDifferentProjectNewFile_Folders_NoUsings_NotSimpleName() { await TestWithMockedGenerateTypeDialog( @@ -1360,7 +1360,7 @@ public interface Goo } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/850101")] - [WpfFact] + [Fact] public async Task GenerateTypeIntoSameLanguageDifferentProjectNewFile_Folders_Usings_DefaultNamespace() { await TestWithMockedGenerateTypeDialog( @@ -1407,7 +1407,7 @@ void Main() } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/850101")] - [WpfFact] + [Fact] public async Task GenerateTypeIntoSameLanguageDifferentProjectNewFile_Folders_NoUsings_NotSimpleName_DefaultNamespace() { await TestWithMockedGenerateTypeDialog( @@ -1449,7 +1449,7 @@ public interface Goo #endregion #endregion #region DifferentLanguage - [WpfFact] + [Fact] public async Task GenerateTypeIntoDifferentLanguageNewFile() { await TestWithMockedGenerateTypeDialog( @@ -1487,7 +1487,7 @@ End Namespace } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/850101")] - [WpfFact] + [Fact] public async Task GenerateTypeIntoDifferentLanguageNewFile_Folders_Usings() { await TestWithMockedGenerateTypeDialog( @@ -1532,7 +1532,7 @@ void Main() } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/850101")] - [WpfFact] + [Fact] public async Task GenerateTypeIntoDifferentLanguageNewFile_Folders_NoUsings_NotSimpleName() { await TestWithMockedGenerateTypeDialog( @@ -1571,7 +1571,7 @@ End Namespace } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/850101")] - [WpfFact] + [Fact] public async Task GenerateTypeIntoDifferentLanguageNewFile_Folders_Usings_RootNamespace() { await TestWithMockedGenerateTypeDialog( @@ -1617,7 +1617,7 @@ void Main() } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/850101")] - [WpfFact] + [Fact] public async Task GenerateTypeIntoDifferentLanguageNewFile_Folders_NoUsings_NotSimpleName_RootNamespace() { await TestWithMockedGenerateTypeDialog( @@ -1657,7 +1657,7 @@ End Namespace } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/850101")] - [WpfFact] + [Fact] public async Task GenerateTypeIntoDifferentLanguageNewFile_Folders_NoUsings_NotSimpleName_RootNamespace_ProjectReference() { await TestWithMockedGenerateTypeDialog( @@ -1703,7 +1703,7 @@ End Namespace } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/858826")] - [WpfFact] + [Fact] public async Task GenerateTypeIntoDifferentLanguageNewFileAdjustFileExtension() { await TestWithMockedGenerateTypeDialog( @@ -1921,7 +1921,7 @@ End Namespace [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/861362")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/869593")] - [WpfFact] + [Fact] public async Task GenerateModuleFromCSharpToVisualBasicInTypeContext() { await TestWithMockedGenerateTypeDialog( @@ -2938,7 +2938,7 @@ static void Main(string[] args) assertGenerateTypeDialogOptions: new GenerateTypeDialogOptions(false, TypeKindOptions.AllOptions)); } - [WpfFact] + [Fact] public async Task GenerateDelegateTypeIntoDifferentLanguageNewFile() { await TestWithMockedGenerateTypeDialog( diff --git a/src/Features/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs b/src/Features/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs index da46a65964069..661061678d95e 100644 --- a/src/Features/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs +++ b/src/Features/CSharpTest/ImplementInterface/ImplementInterfaceTests.cs @@ -7216,7 +7216,7 @@ public string this[int i] #if false [WorkItem(13677)] - [WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsImplementInterface)] public async Task TestNoGenerateInVenusCase2() { await TestMissingAsync( diff --git a/src/Features/CSharpTest/IntroduceVariable/IntroduceVariableTests.cs b/src/Features/CSharpTest/IntroduceVariable/IntroduceVariableTests.cs index e0feb754abe97..82af243d9e711 100644 --- a/src/Features/CSharpTest/IntroduceVariable/IntroduceVariableTests.cs +++ b/src/Features/CSharpTest/IntroduceVariable/IntroduceVariableTests.cs @@ -1125,7 +1125,7 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/552389")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/540482")] - [WpfFact(Skip = "552389")] + [Fact(Skip = "552389")] public async Task TestConstantForFixedBufferInitializer() { await TestInRegularAndScriptAsync( diff --git a/src/Features/CSharpTest/InvertIf/InvertIfTests.cs b/src/Features/CSharpTest/InvertIf/InvertIfTests.cs index 23feb4e4df07c..5988e83158ba8 100644 --- a/src/Features/CSharpTest/InvertIf/InvertIfTests.cs +++ b/src/Features/CSharpTest/InvertIf/InvertIfTests.cs @@ -133,7 +133,7 @@ await TestFixOneAsync( @"if (!a) { b(); } else { a(); }"); } - [WpfFact(Skip = "https://github.com/dotnet/roslyn/issues/26427")] + [Fact(Skip = "https://github.com/dotnet/roslyn/issues/26427")] public async Task TestSingleLine_DoubleParenthesesWithInnerTrivia() { await TestFixOneAsync( diff --git a/src/Features/CSharpTest/MoveType/MoveTypeTests.ActionCountTests.cs b/src/Features/CSharpTest/MoveType/MoveTypeTests.ActionCountTests.cs index 121d81fbe8f3d..8cd01ec060c28 100644 --- a/src/Features/CSharpTest/MoveType/MoveTypeTests.ActionCountTests.cs +++ b/src/Features/CSharpTest/MoveType/MoveTypeTests.ActionCountTests.cs @@ -14,7 +14,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeActions.MoveType [Trait(Traits.Feature, Traits.Features.CodeActionsMoveType)] public partial class MoveTypeTests : CSharpMoveTypeTestsBase { - [WpfFact] + [Fact] public async Task MoveType_ActionCounts_RenameOnly() { var code = @@ -28,7 +28,7 @@ class Class1[||] await TestActionCountAsync(code, count: 2); } - [WpfFact] + [Fact] public async Task MoveType_AvailableBeforeHeader() { var code = @@ -42,7 +42,7 @@ class Class1 await TestActionCountAsync(code, count: 2); } - [WpfFact] + [Fact] public async Task MoveType_AvailableBeforeAttributeOnHeader() { var code = @@ -56,7 +56,7 @@ class Class1 await TestActionCountAsync(code, count: 2); } - [WpfFact] + [Fact] public async Task MoveType_AvailableOnHeaderIncludingWhitespaceAndAttribute() { var code = @@ -70,7 +70,7 @@ class Class1 await TestActionCountAsync(code, count: 2); } - [WpfFact] + [Fact] public async Task MoveType_AvailableAfterHeader() { var code = @@ -83,7 +83,7 @@ class Class1 await TestActionCountAsync(code, count: 2); } - [WpfFact] + [Fact] public async Task MoveType_AvailableIncludingDocumentationCommentAndHeader() { var code = @@ -99,7 +99,7 @@ class Class1|] await TestActionCountAsync(code, count: 2); } - [WpfFact] + [Fact] public async Task MoveType_AvailableIncludingDocumentationCommentAndAttributeAndHeader() { var code = @@ -117,7 +117,7 @@ class Class1|] await TestActionCountAsync(code, count: 2); } - [WpfFact] + [Fact] public async Task MoveType_NotAvailableBeforeType() { var code = @@ -130,7 +130,7 @@ class Class1 await TestMissingInRegularAndScriptAsync(code); } - [WpfFact] + [Fact] public async Task MoveType_NotAvailableInsideType() { var code = @@ -146,7 +146,7 @@ void M() await TestMissingInRegularAndScriptAsync(code); } - [WpfFact] + [Fact] public async Task MoveType_NotAvailableAfterType() { var code = @@ -166,7 +166,7 @@ void M() await TestMissingInRegularAndScriptAsync(code); } - [WpfFact] + [Fact] public async Task MoveType_NotAvailableAroundDocumentationCommentAboveHeader() { var code = @@ -182,7 +182,7 @@ class Class1 await TestMissingInRegularAndScriptAsync(code); } - [WpfFact] + [Fact] public async Task MoveType_NotAvailableAroundAttributeAboveHeader() { var code = @@ -197,7 +197,7 @@ class Class1 await TestMissingInRegularAndScriptAsync(code); } - [WpfFact] + [Fact] public async Task MoveType_NotAvailableAroundDocumentationCommentAndAttributeAboveHeader() { var code = @@ -215,7 +215,7 @@ class Class1 await TestMissingInRegularAndScriptAsync(code); } - [WpfFact] + [Fact] public async Task MoveType_NotAvailableInsideDocumentationCommentAndAttributeAboveHeader() { var code = @@ -233,7 +233,7 @@ class Class1 await TestMissingInRegularAndScriptAsync(code); } - [WpfFact] + [Fact] public async Task MoveType_ActionCounts_MoveOnly() { var code = @@ -251,7 +251,7 @@ class test1 /* this matches file name assigned by TestWorkspace*/ await TestActionCountAsync(code, count: 1); } - [WpfFact] + [Fact] public async Task MoveType_ActionCounts_RenameAndMove() { var code = @@ -269,7 +269,7 @@ class Class2 await TestActionCountAsync(code, count: 3); } - [WpfFact] + [Fact] public async Task MoveType_ActionCounts_All() { var code = diff --git a/src/Features/CSharpTest/MoveType/MoveTypeTests.MoveScope.cs b/src/Features/CSharpTest/MoveType/MoveTypeTests.MoveScope.cs index 1418042d5baee..d2f7194dcecf9 100644 --- a/src/Features/CSharpTest/MoveType/MoveTypeTests.MoveScope.cs +++ b/src/Features/CSharpTest/MoveType/MoveTypeTests.MoveScope.cs @@ -20,7 +20,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeActions.MoveType [Trait(Traits.Feature, Traits.Features.CodeActionsMoveType)] public partial class MoveTypeTests : CSharpMoveTypeTestsBase { - [WpfFact] + [Fact] public Task MoveType_NamespaceScope_SingleItem() { var code = @@ -42,7 +42,7 @@ class Class1 return TestNamespaceMove(code, expected, expectOperation: false); } - [WpfFact] + [Fact] public Task MoveType_NamespaceScope_SingleItemNamespaceComment() { var code = @@ -66,7 +66,7 @@ class Class1 return TestNamespaceMove(code, expected, expectOperation: false); } - [WpfFact] + [Fact] public Task MoveType_NamespaceScope_ItemAtTop() { var code = @@ -99,7 +99,7 @@ class Class2 return TestNamespaceMove(code, expected); } - [WpfFact] + [Fact] public Task MoveType_NamespaceScope_ItemAtTopNamespaceComment() { var code = @@ -134,7 +134,7 @@ class Class2 return TestNamespaceMove(code, expected); } - [WpfFact] + [Fact] public Task MoveType_NamespaceScope_ItemAtTopWithComments() { var code = @@ -171,7 +171,7 @@ class Class2 return TestNamespaceMove(code, expected); } - [WpfFact] + [Fact] public Task MoveType_NamespaceScope_ItemAtTopWithXmlComments() { var code = @@ -216,7 +216,7 @@ class Class2 return TestNamespaceMove(code, expected); } - [WpfFact] + [Fact] public Task MoveType_NamespaceScope_ItemAtBottom() { var code = @@ -249,7 +249,7 @@ class Class2 return TestNamespaceMove(code, expected); } - [WpfFact] + [Fact] public Task MoveType_NamespaceScope_ItemAtBottomNamespaceComments() { var code = @@ -284,7 +284,7 @@ class Class2 return TestNamespaceMove(code, expected); } - [WpfFact] + [Fact] public Task MoveType_NamespaceScope_ItemAtBottomWithComments() { var code = @@ -321,7 +321,7 @@ class Class2 return TestNamespaceMove(code, expected); } - [WpfFact] + [Fact] public Task MoveType_NamespaceScope_ItemAtBottomWithXmlComments() { var code = @@ -366,7 +366,7 @@ class Class2 return TestNamespaceMove(code, expected); } - [WpfFact] + [Fact] public Task MoveType_NamespaceScope_ItemInMiddle() { var code = @@ -426,7 +426,7 @@ class Class5 return TestNamespaceMove(code, expected); } - [WpfFact] + [Fact] public Task MoveType_NamespaceScope_ItemInMiddleNamespaceComment() { var code = @@ -488,7 +488,7 @@ class Class5 return TestNamespaceMove(code, expected); } - [WpfFact] + [Fact] public Task MoveType_NamespaceScope_ItemInMiddleWithComments() { var code = @@ -558,7 +558,7 @@ class Class5 return TestNamespaceMove(code, expected); } - [WpfFact] + [Fact] public Task MoveType_NamespaceScope_ItemInMiddleWithXmlComments() { var code = @@ -648,7 +648,7 @@ class Class5 return TestNamespaceMove(code, expected); } - [WpfFact] + [Fact] public Task MoveType_NamespaceScope_ItemInMiddleWithInterface() { var code = @@ -722,7 +722,7 @@ class Class5 return TestNamespaceMove(code, expected); } - [WpfFact] + [Fact] public Task MoveType_NamespaceScope_TwoItemsInDifferentNamespace() { var code = @@ -758,7 +758,7 @@ class Class2 return TestNamespaceMove(code, expected, expectOperation: false); } - [WpfFact] + [Fact] public Task MoveType_NamespaceScope_ItemsInDifferentNamespace() { var code = @@ -805,7 +805,7 @@ class Class2 return TestNamespaceMove(code, expected); } - [WpfFact] + [Fact] public Task MoveType_NamespaceScope_NestedNamespaces() { var code = @@ -850,7 +850,7 @@ class C3 return TestNamespaceMove(code, expected); } - [WpfFact] + [Fact] public Task MoveType_NamespaceScope_NestedNamespaces2() { var code = diff --git a/src/Features/CSharpTest/MoveType/MoveTypeTests.MoveToNewFile.cs b/src/Features/CSharpTest/MoveType/MoveTypeTests.MoveToNewFile.cs index c9a289ffbe29c..f49cccda16fbb 100644 --- a/src/Features/CSharpTest/MoveType/MoveTypeTests.MoveToNewFile.cs +++ b/src/Features/CSharpTest/MoveType/MoveTypeTests.MoveToNewFile.cs @@ -16,7 +16,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeActions.MoveType [Trait(Traits.Feature, Traits.Features.CodeActionsMoveType)] public partial class MoveTypeTests : CSharpMoveTypeTestsBase { - [WpfFact] + [Fact] public async Task TestMissing_OnMatchingFileName() { var code = @@ -25,7 +25,7 @@ public async Task TestMissing_OnMatchingFileName() await TestMissingInRegularAndScriptAsync(code); } - [WpfFact] + [Fact] public async Task TestMissing_Nested_OnMatchingFileName_Simple() { var code = @@ -37,7 +37,7 @@ public async Task TestMissing_Nested_OnMatchingFileName_Simple() await TestMissingInRegularAndScriptAsync(code); } - [WpfFact] + [Fact] public async Task TestMatchingFileName_CaseSensitive() { var code = @@ -46,7 +46,7 @@ public async Task TestMatchingFileName_CaseSensitive() await TestActionCountAsync(code, count: 2); } - [WpfFact] + [Fact] public async Task TestForSpans1() { var code = @@ -56,7 +56,7 @@ class Class2 { }"; await TestActionCountAsync(code, count: 3); } - [WpfFact] + [Fact] public async Task TestForSpans2() { var code = @@ -71,7 +71,7 @@ class Class2 { }"; await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/14008")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/14008")] public async Task TestMoveToNewFileWithFolders() { var code = @@ -96,7 +96,7 @@ await TestMoveTypeToNewFileAsync( destinationDocumentText, destinationDocumentContainers: ImmutableArray.Create("A", "B")); } - [WpfFact] + [Fact] public async Task TestForSpans3() { var code = @@ -106,7 +106,7 @@ class Class2 { }"; await TestActionCountAsync(code, count: 3); } - [WpfFact] + [Fact] public async Task TestForSpans4() { var code = @@ -121,7 +121,7 @@ class Class2 { }"; await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact] + [Fact] public async Task MoveTypeWithNoContainerNamespace() { var code = @@ -136,7 +136,7 @@ class Class2 { }"; await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact] + [Fact] public async Task MoveTypeWithWithUsingsAndNoContainerNamespace() { var code = @@ -160,7 +160,7 @@ class Class1 { } await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact] + [Fact] public async Task MoveTypeWithWithMembers() { var code = @@ -197,7 +197,7 @@ void Print(int x) await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact] + [Fact] public async Task MoveTypeWithWithMembers2() { var code = @@ -249,7 +249,7 @@ void Print(int x) await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact] + [Fact] public async Task MoveAnInterface() { var code = @@ -264,7 +264,7 @@ class Class2 { }"; await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact] + [Fact] public async Task MoveAStruct() { var code = @@ -279,7 +279,7 @@ class Class2 { }"; await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact] + [Fact] public async Task MoveAnEnum() { var code = @@ -294,7 +294,7 @@ class Class2 { }"; await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact] + [Fact] public async Task MoveTypeWithWithContainerNamespace() { var code = @@ -320,7 +320,7 @@ class Class1 { } await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact] + [Fact] public async Task MoveTypeWithWithFileScopedNamespace() { var code = @@ -345,7 +345,7 @@ class Class1 { } await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact] + [Fact] public async Task MoveNestedTypeToNewFile_Simple() { var code = @@ -381,7 +381,7 @@ class Class2 { } await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact] + [Fact] public async Task MoveNestedTypePreserveModifiers() { var code = @@ -417,7 +417,7 @@ class Class2 { } await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/14004")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/14004")] public async Task MoveNestedTypeToNewFile_Attributes1() { var code = @@ -457,7 +457,7 @@ class Class2 { } await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/14484")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/14484")] public async Task MoveNestedTypeToNewFile_Comments1() { var code = @@ -499,7 +499,7 @@ await TestMoveTypeToNewFileAsync( code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact] + [Fact] public async Task MoveNestedTypeToNewFile_Simple_DottedName() { var code = @@ -535,7 +535,7 @@ class Class2 { } await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText, index: 1); } - [WpfFact] + [Fact] public async Task MoveNestedTypeToNewFile_ParentHasOtherMembers() { var code = @@ -578,7 +578,7 @@ class Class2 { } await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact] + [Fact] public async Task MoveNestedTypeToNewFile_HasOtherTopLevelMembers() { var code = @@ -628,7 +628,7 @@ class Class2 { } await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact] + [Fact] public async Task MoveNestedTypeToNewFile_HasMembers() { var code = @@ -676,7 +676,7 @@ public void InnerMethod() { } await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/13969")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/13969")] public async Task MoveTypeInFileWithComplexHierarchy() { var code = @@ -790,7 +790,7 @@ class InnerClass3 await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact] + [Fact] public async Task MoveTypeUsings1() { var code = @@ -833,7 +833,7 @@ class Inner { } [WorkItem("https://github.com/dotnet/roslyn/issues/16283")] - [WpfFact] + [Fact] public async Task TestLeadingTrivia1() { var code = @@ -870,7 +870,7 @@ await TestMoveTypeToNewFileAsync( } [WorkItem("https://github.com/dotnet/roslyn/issues/17171")] - [WpfFact] + [Fact] public async Task TestInsertFinalNewLine() { var code = @@ -909,7 +909,7 @@ await TestMoveTypeToNewFileAsync( } [WorkItem("https://github.com/dotnet/roslyn/issues/17171")] - [WpfFact] + [Fact] public async Task TestInsertFinalNewLine2() { var code = @@ -947,7 +947,7 @@ await TestMoveTypeToNewFileAsync( } [WorkItem("https://github.com/dotnet/roslyn/issues/16282")] - [WpfFact] + [Fact] public async Task MoveTypeRemoveOuterInheritanceTypes() { var code = @@ -977,7 +977,7 @@ await TestMoveTypeToNewFileAsync( } [WorkItem("https://github.com/dotnet/roslyn/issues/17930")] - [WpfFact] + [Fact] public async Task MoveTypeWithDirectives1() { var code = @@ -1030,7 +1030,7 @@ await TestMoveTypeToNewFileAsync( } [WorkItem("https://github.com/dotnet/roslyn/issues/17930")] - [WpfFact] + [Fact] public async Task MoveTypeWithDirectives2() { var code = @@ -1088,7 +1088,7 @@ await TestMoveTypeToNewFileAsync( } [WorkItem("https://github.com/dotnet/roslyn/issues/21456")] - [WpfFact] + [Fact] public async Task TestLeadingBlankLines1() { var code = @@ -1141,7 +1141,7 @@ await TestMoveTypeToNewFileAsync( } [WorkItem("https://github.com/dotnet/roslyn/issues/21456")] - [WpfFact] + [Fact] public async Task TestLeadingBlankLines2() { var code = @@ -1194,7 +1194,7 @@ await TestMoveTypeToNewFileAsync( } [WorkItem("https://github.com/dotnet/roslyn/issues/31377")] - [WpfFact] + [Fact] public async Task TestLeadingCommentInContainer() { var code = @@ -1247,7 +1247,7 @@ await TestMoveTypeToNewFileAsync( } [WorkItem("https://github.com/dotnet/roslyn/issues/31377")] - [WpfFact] + [Fact] public async Task TestLeadingCommentInContainer2() { var code = @@ -1298,7 +1298,7 @@ await TestMoveTypeToNewFileAsync( } [WorkItem("https://github.com/dotnet/roslyn/issues/31377")] - [WpfFact] + [Fact] public async Task TestTrailingCommentInContainer() { var code = @@ -1351,7 +1351,7 @@ await TestMoveTypeToNewFileAsync( } [WorkItem("https://github.com/dotnet/roslyn/issues/31377")] - [WpfFact] + [Fact] public async Task TestTrailingCommentInContainer2() { var code = @@ -1401,7 +1401,7 @@ await TestMoveTypeToNewFileAsync( } [WorkItem("https://github.com/dotnet/roslyn/issues/50329")] - [WpfFact] + [Fact] public async Task MoveRecordToNewFilePreserveUsings() { var code = @@ -1421,7 +1421,7 @@ record CacheContext(String Message); await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact] + [Fact] public async Task MoveClassToNewFilePreserveUsings_PrimaryConstructor() { var code = @@ -1441,7 +1441,7 @@ class CacheContext(String Message); await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact] + [Fact] public async Task MoveStructToNewFilePreserveUsings_PrimaryConstructor() { var code = @@ -1461,7 +1461,7 @@ struct CacheContext(String Message); await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact] + [Fact] public async Task MoveInterfaceToNewFilePreserveUsings_PrimaryConstructor() { var code = @@ -1481,7 +1481,7 @@ class Program { }"; await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact] + [Fact] public async Task MoveClassInTopLevelStatements() { var code = @" @@ -1513,7 +1513,7 @@ class [||]C await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact] + [Fact] public async Task MissingInTopLevelStatementsOnly() { var code = @" @@ -1527,7 +1527,7 @@ public async Task MissingInTopLevelStatementsOnly() await TestMissingAsync(code); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/55544")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/55544")] public async Task MoveInNamespace_WithAttributes1() { var code = @" @@ -1567,7 +1567,7 @@ class B await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/55544")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/55544")] public async Task MoveInNamespace_WithAttributes2() { var code = @" @@ -1609,7 +1609,7 @@ class B await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/55544")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/55544")] public async Task MoveInNamespace_WithAttributes3() { var code = @" @@ -1646,7 +1646,7 @@ class B await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/55544")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/55544")] public async Task MoveTopLevel_WithAttributes1() { var code = @" @@ -1674,7 +1674,7 @@ class A await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/55544")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/55544")] public async Task MoveTopLevel_WithAttributes2() { var code = @" diff --git a/src/Features/CSharpTest/MoveType/MoveTypeTests.RenameFile.cs b/src/Features/CSharpTest/MoveType/MoveTypeTests.RenameFile.cs index 88cb85d11e151..4e60c486cfb19 100644 --- a/src/Features/CSharpTest/MoveType/MoveTypeTests.RenameFile.cs +++ b/src/Features/CSharpTest/MoveType/MoveTypeTests.RenameFile.cs @@ -14,7 +14,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeActions.MoveType [Trait(Traits.Feature, Traits.Features.CodeActionsMoveType)] public partial class MoveTypeTests : CSharpMoveTypeTestsBase { - [WpfFact] + [Fact] public async Task SingleClassInFile_RenameFile() { var code = @@ -25,7 +25,7 @@ public async Task SingleClassInFile_RenameFile() await TestRenameFileToMatchTypeAsync(code, expectedDocumentName); } - [WpfFact] + [Fact] public async Task MoreThanOneTypeInFile_RenameFile() { var code = @@ -40,7 +40,7 @@ class Inner { } } [WorkItem("https://github.com/dotnet/roslyn/issues/16284")] - [WpfFact] + [Fact] public async Task MoreThanOneTypeInFile_RenameFile_InnerType() { var code = @@ -54,7 +54,7 @@ public async Task MoreThanOneTypeInFile_RenameFile_InnerType() await TestRenameFileToMatchTypeAsync(code, expectedDocumentName); } - [WpfFact] + [Fact] public async Task TestRenameFileWithFolders() { var code = @@ -76,7 +76,7 @@ await TestRenameFileToMatchTypeAsync(code, expectedDocumentName, destinationDocumentContainers: new[] { "A", "B" }); } - [WpfFact] + [Fact] public async Task TestMissing_TypeNameMatchesFileName_RenameFile() { // testworkspace creates files like test1.cs, test2.cs and so on.. @@ -87,7 +87,7 @@ public async Task TestMissing_TypeNameMatchesFileName_RenameFile() await TestRenameFileToMatchTypeAsync(code, expectedCodeAction: false); } - [WpfFact] + [Fact] public async Task TestMissing_MultipleTopLevelTypesInFileAndAtleastOneMatchesFileName_RenameFile() { var code = @@ -97,7 +97,7 @@ class test1 { }"; await TestRenameFileToMatchTypeAsync(code, expectedCodeAction: false); } - [WpfFact] + [Fact] public async Task MultipleTopLevelTypesInFileAndNoneMatchFileName_RenameFile() { var code = @@ -109,7 +109,7 @@ class Class2 { }"; await TestRenameFileToMatchTypeAsync(code, expectedDocumentName); } - [WpfFact] + [Fact] public async Task MultipleTopLevelTypesInFileAndNoneMatchFileName2_RenameFile() { var code = @@ -121,7 +121,7 @@ public async Task MultipleTopLevelTypesInFileAndNoneMatchFileName2_RenameFile() await TestRenameFileToMatchTypeAsync(code, expectedDocumentName); } - [WpfFact] + [Fact] public async Task NestedFile_Simple_RenameFile() { var code = @@ -135,7 +135,7 @@ public async Task NestedFile_Simple_RenameFile() await TestRenameFileToMatchTypeAsync(code, expectedDocumentName); } - [WpfFact] + [Fact] public async Task NestedFile_DottedName_RenameFile() { var code = diff --git a/src/Features/CSharpTest/MoveType/MoveTypeTests.RenameType.cs b/src/Features/CSharpTest/MoveType/MoveTypeTests.RenameType.cs index af76ec8126d7a..44ecaea10c5ea 100644 --- a/src/Features/CSharpTest/MoveType/MoveTypeTests.RenameType.cs +++ b/src/Features/CSharpTest/MoveType/MoveTypeTests.RenameType.cs @@ -14,7 +14,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeActions.MoveType [Trait(Traits.Feature, Traits.Features.CodeActionsMoveType)] public partial class MoveTypeTests : CSharpMoveTypeTestsBase { - [WpfFact] + [Fact] public async Task SingleClassInFile_RenameType() { var code = @@ -26,7 +26,7 @@ public async Task SingleClassInFile_RenameType() await TestRenameTypeToMatchFileAsync(code, codeWithTypeRenamedToMatchFileName); } - [WpfFact] + [Fact] public async Task MoreThanOneTypeInFile_RenameType() { var code = @@ -44,7 +44,7 @@ class Inner { } await TestRenameTypeToMatchFileAsync(code, codeWithTypeRenamedToMatchFileName); } - [WpfFact] + [Fact] public async Task TestMissing_TypeNameMatchesFileName_RenameType() { // testworkspace creates files like test1.cs, test2.cs and so on.. @@ -55,7 +55,7 @@ public async Task TestMissing_TypeNameMatchesFileName_RenameType() await TestRenameTypeToMatchFileAsync(code, expectedCodeAction: false); } - [WpfFact] + [Fact] public async Task TestMissing_MultipleTopLevelTypesInFileAndAtleastOneMatchesFileName_RenameType() { var code = @@ -65,7 +65,7 @@ class test1 { }"; await TestRenameTypeToMatchFileAsync(code, expectedCodeAction: false); } - [WpfFact] + [Fact] public async Task MultipleTopLevelTypesInFileAndNoneMatchFileName1_RenameType() { var code = @@ -79,7 +79,7 @@ class Class2 { }"; await TestRenameTypeToMatchFileAsync(code, codeWithTypeRenamedToMatchFileName); } - [WpfFact] + [Fact] public async Task MultipleTopLevelTypesInFileAndNoneMatchFileName2_RenameType() { var code = @@ -93,21 +93,21 @@ class [|test1|] { }"; await TestRenameTypeToMatchFileAsync(code, codeWithTypeRenamedToMatchFileName); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/40043")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40043")] public async Task NothingOfferedWhenTypeHasNoNameYet1() { var code = @"class[||]"; await TestMissingAsync(code); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/40043")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40043")] public async Task NothingOfferedWhenTypeHasNoNameYet2() { var code = @"class [||]"; await TestMissingAsync(code); } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/40043")] + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/40043")] public async Task NothingOfferedWhenTypeHasNoNameYet3() { var code = @"class [||] { }"; diff --git a/src/Features/CSharpTest/RemoveUnnecessaryCast/RemoveUnnecessaryCastTests_AsTests.cs b/src/Features/CSharpTest/RemoveUnnecessaryCast/RemoveUnnecessaryCastTests_AsTests.cs index 44f89c8f4d145..a56d47c604131 100644 --- a/src/Features/CSharpTest/RemoveUnnecessaryCast/RemoveUnnecessaryCastTests_AsTests.cs +++ b/src/Features/CSharpTest/RemoveUnnecessaryCast/RemoveUnnecessaryCastTests_AsTests.cs @@ -594,7 +594,7 @@ static void Main() } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545595")] - [WpfFact(Skip = "529787")] + [Fact(Skip = "529787")] public async Task RemoveUnneededCastInCollectionInitializer() { await TestInRegularAndScriptAsync( @@ -624,7 +624,7 @@ static void Main() } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529787")] - [WpfFact(Skip = "529787")] + [Fact(Skip = "529787")] public async Task DoNotRemoveNecessaryCastWhichInCollectionInitializer1() { await TestMissingInRegularAndScriptAsync( @@ -653,7 +653,7 @@ static void Main() } [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529787")] - [WpfFact(Skip = "529787")] + [Fact(Skip = "529787")] public async Task DoNotRemoveNecessaryCastWhichInCollectionInitializer2() { await TestMissingInRegularAndScriptAsync( diff --git a/src/Features/CSharpTest/SyncNamespace/SyncNamespaceTests_ChangeNamespace.cs b/src/Features/CSharpTest/SyncNamespace/SyncNamespaceTests_ChangeNamespace.cs index 8f7a76ab071b7..1bb9c4897095e 100644 --- a/src/Features/CSharpTest/SyncNamespace/SyncNamespaceTests_ChangeNamespace.cs +++ b/src/Features/CSharpTest/SyncNamespace/SyncNamespaceTests_ChangeNamespace.cs @@ -15,7 +15,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeActions.SyncNamespa [Trait(Traits.Feature, Traits.Features.CodeActionsSyncNamespace)] public partial class SyncNamespaceTests : CSharpSyncNamespaceTestsBase { - [WpfFact] + [Fact] public async Task ChangeNamespace_InvalidFolderName1() { var defaultNamespace = "A"; @@ -40,7 +40,7 @@ class Class1 await TestChangeNamespaceAsync(code, expectedSourceOriginal: null); } - [WpfFact] + [Fact] public async Task ChangeNamespace_InvalidFolderName2() { var defaultNamespace = "A"; @@ -65,7 +65,7 @@ class Class1 await TestChangeNamespaceAsync(code, expectedSourceOriginal: null); } - [WpfFact] + [Fact] public async Task ChangeNamespace_SingleDocumentNoReference() { var defaultNamespace = "A"; @@ -96,7 +96,7 @@ class Class1 await TestChangeNamespaceAsync(code, expectedSourceOriginal); } - [WpfFact] + [Fact] public async Task ChangeNamespace_SingleDocumentNoReference_FileScopedNamespace() { var defaultNamespace = "A"; @@ -127,7 +127,7 @@ class Class1 await TestChangeNamespaceAsync(code, expectedSourceOriginal); } - [WpfFact] + [Fact] public async Task ChangeNamespace_SingleDocumentLocalReference() { var defaultNamespace = "A"; @@ -178,7 +178,7 @@ void Class1.M1() { } await TestChangeNamespaceAsync(code, expectedSourceOriginal); } - [WpfFact] + [Fact] public async Task ChangeNamespace_WithCrefReference() { var defaultNamespace = "A"; @@ -255,7 +255,7 @@ class RefClass await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact] + [Fact] public async Task ChangeNamespace_WithCrefReferencesInVB() { var defaultNamespace = "A.B.C"; @@ -317,7 +317,7 @@ Public ReadOnly Property C1 As Class1 await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact] + [Fact] public async Task ChangeNamespace_ReferencingTypesDeclaredInOtherDocument() { var defaultNamespace = "A"; @@ -374,7 +374,7 @@ class Class1 await TestChangeNamespaceAsync(code, expectedSourceOriginal); } - [WpfFact] + [Fact] public async Task ChangeNamespace_ReferencingQualifiedTypesDeclaredInOtherDocument() { var defaultNamespace = "A"; @@ -431,7 +431,7 @@ class Class1 await TestChangeNamespaceAsync(code, expectedSourceOriginal); } - [WpfFact] + [Fact] public async Task ChangeNamespace_WithReferencesInOtherDocument() { var defaultNamespace = "A"; @@ -502,7 +502,7 @@ void M1() await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact] + [Fact] public async Task ChangeNamespace_WithQualifiedReferencesInOtherDocument() { var defaultNamespace = "A"; @@ -557,7 +557,7 @@ void Interface1.M1(Interface1 c1){} await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact] + [Fact] public async Task ChangeNamespace_ChangeUsingsInMultipleContainers() { var defaultNamespace = "A"; @@ -628,7 +628,7 @@ class Class2 await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact] + [Fact] public async Task ChangeNamespace_WithAliasReferencesInOtherDocument() { var defaultNamespace = "A"; @@ -702,7 +702,7 @@ void M1() await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact] + [Fact] public async Task ChangeToGlobalNamespace_SingleDocumentNoRef() { var defaultNamespace = ""; @@ -743,7 +743,7 @@ class Class1 await TestChangeNamespaceAsync(code, expectedSourceOriginal); } - [WpfFact] + [Fact] public async Task ChangeToGlobalNamespace_SingleDocumentLocalRef() { var defaultNamespace = ""; @@ -792,7 +792,7 @@ void Class1.M1() { } await TestChangeNamespaceAsync(code, expectedSourceOriginal); } - [WpfFact] + [Fact] public async Task ChangeToGlobalNamespace_WithReferencesInOtherDocument() { var defaultNamespace = ""; @@ -858,7 +858,7 @@ void M1() await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact] + [Fact] public async Task ChangeToGlobalNamespace_WithQualifiedReferencesInOtherDocument() { var defaultNamespace = ""; @@ -909,7 +909,7 @@ void Interface1.M1(Interface1 c1){} await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact] + [Fact] public async Task ChangeToGlobalNamespace_WithReferenceAndConflictDeclarationInOtherDocument() { var defaultNamespace = ""; @@ -966,7 +966,7 @@ class MyClass await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact] + [Fact] public async Task ChangeToGlobalNamespace_ReferencingTypesDeclaredInOtherDocument() { var defaultNamespace = ""; @@ -1021,7 +1021,7 @@ class Class1 await TestChangeNamespaceAsync(code, expectedSourceOriginal); } - [WpfFact] + [Fact] public async Task ChangeToGlobalNamespace_ChangeUsingsInMultipleContainers() { var defaultNamespace = ""; @@ -1088,7 +1088,7 @@ class Class2 await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact] + [Fact] public async Task ChangeToGlobalNamespace_WithAliasReferencesInOtherDocument() { var defaultNamespace = ""; @@ -1159,7 +1159,7 @@ void M1() await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact] + [Fact] public async Task ChangeFromGlobalNamespace_SingleDocumentNoRef() { var defaultNamespace = "A"; @@ -1191,7 +1191,7 @@ class Class1 await TestChangeNamespaceAsync(code, expectedSourceOriginal); } - [WpfFact] + [Fact] public async Task ChangeFromGlobalNamespace_SingleDocumentLocalRef() { var defaultNamespace = "A"; @@ -1237,7 +1237,7 @@ void Class1.M1() { } await TestChangeNamespaceAsync(code, expectedSourceOriginal); } - [WpfFact] + [Fact] public async Task ChangeFromGlobalNamespace_WithReferencesInOtherDocument() { var defaultNamespace = "A"; @@ -1302,7 +1302,7 @@ void M1() await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact] + [Fact] public async Task ChangeFromGlobalNamespace_WithQualifiedReferencesInOtherDocument() { var defaultNamespace = "A"; @@ -1350,7 +1350,7 @@ void Interface1.M1(Interface1 c1){} await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact] + [Fact] public async Task ChangeFromGlobalNamespace_ReferencingQualifiedTypesDeclaredInOtherDocument() { var defaultNamespace = "A"; @@ -1399,7 +1399,7 @@ class Class1 await TestChangeNamespaceAsync(code, expectedSourceOriginal); } - [WpfFact] + [Fact] public async Task ChangeFromGlobalNamespace_ChangeUsingsInMultipleContainers() { var defaultNamespace = "A"; @@ -1469,7 +1469,7 @@ class Class2 await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact] + [Fact] public async Task ChangeFromGlobalNamespace_WithAliasReferencesInOtherDocument() { var defaultNamespace = "A"; @@ -1541,7 +1541,7 @@ void M1() await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact] + [Fact] public async Task ChangeNamespace_WithReferencesInVBDocument() { var defaultNamespace = "A.B.C"; @@ -1587,7 +1587,7 @@ Public ReadOnly Property C1 As Class1 await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact] + [Fact] public async Task ChangeNamespace_WithQualifiedReferencesInVBDocument() { var defaultNamespace = "A.B.C"; @@ -1628,7 +1628,7 @@ Public ReadOnly Property C1 As A.B.C.Class1 await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact] + [Fact] public async Task ChangeFromGlobalNamespace_WithReferencesInVBDocument() { var defaultNamespace = "A"; @@ -1669,7 +1669,7 @@ Public ReadOnly Property C1 As Class1 await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact] + [Fact] public async Task ChangeFromGlobalNamespace_WithCredReferences() { var defaultNamespace = "A"; @@ -1726,7 +1726,7 @@ class Bar await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact] + [Fact] public async Task ChangeToGlobalNamespace_WithReferencesInVBDocument() { var defaultNamespace = ""; @@ -1767,7 +1767,7 @@ Public ReadOnly Property C1 As Class1 await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact] + [Fact] public async Task ChangeToGlobalNamespace_WithReferenceAndConflictDeclarationInVBDocument() { var defaultNamespace = ""; @@ -1816,7 +1816,7 @@ End Class await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact] + [Fact] public async Task ChangeToGlobalNamespace_WithCredReferences() { var defaultNamespace = ""; @@ -1880,7 +1880,7 @@ class RefClass } [WorkItem("https://github.com/dotnet/roslyn/issues/33890")] - [WpfFact] + [Fact] public async Task ChangeNamespace_ExtensionMethodInReducedForm() { var defaultNamespace = "A"; @@ -1936,7 +1936,7 @@ public class Class1 } [WorkItem("https://github.com/dotnet/roslyn/issues/33890")] - [WpfFact] + [Fact] public async Task ChangeNamespace_ExternsionMethodInRegularForm() { var defaultNamespace = "A"; @@ -1992,7 +1992,7 @@ public class Class1 } [WorkItem("https://github.com/dotnet/roslyn/issues/33890")] - [WpfFact] + [Fact] public async Task ChangeNamespace_ContainsBothTypeAndExternsionMethod() { var defaultNamespace = "A"; @@ -2054,7 +2054,7 @@ public class Class1 } [WorkItem("https://github.com/dotnet/roslyn/issues/33890")] - [WpfFact] + [Fact] public async Task ChangeNamespace_WithExtensionMethodReferencesInVBDocument() { var defaultNamespace = "A.B.C"; @@ -2112,7 +2112,7 @@ End Function } [WorkItem("https://github.com/dotnet/roslyn/issues/37891")] - [WpfFact] + [Fact] public async Task ChangeNamespace_WithMemberAccessReferencesInOtherDocument() { var defaultNamespace = "A"; @@ -2176,7 +2176,7 @@ Enum1 M1() } [WorkItem("https://github.com/dotnet/roslyn/issues/37891")] - [WpfFact] + [Fact] public async Task ChangeToGlobalNamespace_WithMemberAccessReferencesInOtherDocument() { var defaultNamespace = ""; @@ -2235,7 +2235,7 @@ Enum1 M1() } [WorkItem("https://github.com/dotnet/roslyn/issues/37891")] - [WpfFact] + [Fact] public async Task ChangeNamespace_WithMemberAccessReferencesInVBDocument() { var defaultNamespace = "A.B.C"; @@ -2287,7 +2287,7 @@ End Sub } [WorkItem("https://github.com/dotnet/roslyn/issues/37891")] - [WpfFact] + [Fact] public async Task ChangeToGlobalNamespace_WithMemberAccessReferencesInVBDocument() { var defaultNamespace = ""; @@ -2336,7 +2336,7 @@ End Sub await TestChangeNamespaceAsync(code, expectedSourceOriginal, expectedSourceReference); } - [WpfFact, WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1889796")] + [Fact, WorkItem("https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1889796")] public async Task ChangeNamespace_DoesNotThrowInDuplicateProgramDeclaration() { var defaultNamespace = "A"; diff --git a/src/Features/CSharpTest/SyncNamespace/SyncNamespaceTests_MoveFile.cs b/src/Features/CSharpTest/SyncNamespace/SyncNamespaceTests_MoveFile.cs index 14a5d419a30bf..3837927fcad60 100644 --- a/src/Features/CSharpTest/SyncNamespace/SyncNamespaceTests_MoveFile.cs +++ b/src/Features/CSharpTest/SyncNamespace/SyncNamespaceTests_MoveFile.cs @@ -16,7 +16,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeActions.SyncNamespa [Trait(Traits.Feature, Traits.Features.CodeActionsSyncNamespace)] public partial class SyncNamespaceTests : CSharpSyncNamespaceTestsBase { - [WpfFact] + [Fact] public async Task MoveFile_DeclarationNotContainedInDefaultNamespace() { // No "move file" action because default namespace is not container of declared namespace @@ -43,7 +43,7 @@ class Class1 await TestMoveFileToMatchNamespace(code, expectedFolders); } - [WpfFact] + [Fact] public async Task MoveFile_DeclarationNotContainedInDefaultNamespace_FileScopedNamespace() { // No "move file" action because default namespace is not container of declared namespace @@ -69,7 +69,7 @@ class Class1 await TestMoveFileToMatchNamespace(code, expectedFolders); } - [WpfFact] + [Fact] public async Task MoveFile_SingleAction1() { // current path is \ @@ -101,7 +101,7 @@ class Class1 await TestMoveFileToMatchNamespace(code, expectedFolders); } - [WpfFact] + [Fact] public async Task MoveFile_SingleAction2() { // current path is \ @@ -142,7 +142,7 @@ class Class2 await TestMoveFileToMatchNamespace(code, expectedFolders); } - [WpfFact] + [Fact] public async Task MoveFile_MoveToRoot() { // current path is \A\B\C\ @@ -174,7 +174,7 @@ class Class2 await TestMoveFileToMatchNamespace(code, expectedFolders); } - [WpfFact] + [Fact] public async Task MoveFile_MultipleAction1() { // current path is \ @@ -216,7 +216,7 @@ class Class2 await TestMoveFileToMatchNamespace(code, expectedFolders); } - [WpfFact] + [Fact] public async Task MoveFile_MultipleAction2() { // current path is \ @@ -269,7 +269,7 @@ class Class2 await TestMoveFileToMatchNamespace(code, expectedFolders); } - [WpfFact] + [Fact] public async Task MoveFile_FromOneFolderToAnother1() { var defaultNamespace = "A"; @@ -307,7 +307,7 @@ class Class2 await TestMoveFileToMatchNamespace(code, expectedFolders); } - [WpfFact] + [Fact] public async Task MoveFile_FromOneFolderToAnother2() { var defaultNamespace = "A"; @@ -344,7 +344,7 @@ class Class2 await TestMoveFileToMatchNamespace(code, expectedFolders); } - [WpfFact] + [Fact] public async Task MoveFile_FromOneFolderToAnother2_FileScopedNamespace() { var defaultNamespace = "A"; diff --git a/src/Features/CSharpTest/SyncNamespace/SyncNamespaceTests_NoAction.cs b/src/Features/CSharpTest/SyncNamespace/SyncNamespaceTests_NoAction.cs index 1667db5d356d6..682c4e3ded638 100644 --- a/src/Features/CSharpTest/SyncNamespace/SyncNamespaceTests_NoAction.cs +++ b/src/Features/CSharpTest/SyncNamespace/SyncNamespaceTests_NoAction.cs @@ -16,7 +16,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeActions.SyncNamespa [Trait(Traits.Feature, Traits.Features.CodeActionsSyncNamespace)] public partial class SyncNamespaceTests : CSharpSyncNamespaceTestsBase { - [WpfFact] + [Fact] public async Task NoAction_NotOnNamespaceDeclaration() { var folders = new[] { "A", "B" }; @@ -39,7 +39,7 @@ class [||]Class1 await TestMissingInRegularAndScriptAsync(code); } - [WpfFact] + [Fact] public async Task NoAction_NotOnNamespaceDeclaration_FileScopedNamespace() { var folders = new[] { "A", "B" }; @@ -62,7 +62,7 @@ class [||]Class1 await TestMissingInRegularAndScriptAsync(code); } - [WpfFact] + [Fact] public async Task NoAction_NotOnFirstMemberInGlobal() { var folders = new[] { "A" }; @@ -87,7 +87,7 @@ class [||]Class2 await TestMissingInRegularAndScriptAsync(code); } - [WpfFact] + [Fact] public async Task NoAction_MultipleNamespaceDeclarations() { var folders = new[] { "A", "B" }; @@ -118,7 +118,7 @@ class Class1 await TestMissingInRegularAndScriptAsync(code); } - [WpfFact] + [Fact] public async Task NoAction_MembersInBothGlobalAndNamespaceDeclaration_CursorOnNamespace() { var folders = new[] { "A", "B" }; @@ -146,7 +146,7 @@ class Class2 await TestMissingInRegularAndScriptAsync(code); } - [WpfFact] + [Fact] public async Task NoAction_MembersInBothGlobalAndNamespaceDeclaration_CursorOnFirstGlobalMember() { var folders = new[] { "A", "B" }; @@ -174,7 +174,7 @@ class Class2 await TestMissingInRegularAndScriptAsync(code); } - [WpfFact] + [Fact] public async Task NoAction_NestedNamespaceDeclarations() { var folders = new[] { "A", "B" }; @@ -201,7 +201,7 @@ class Class1 await TestMissingInRegularAndScriptAsync(code); } - [WpfFact] + [Fact] public async Task NoAction_InvalidNamespaceIdentifier() { var folders = new[] { "A", "B" }; @@ -225,7 +225,7 @@ class Class1 await TestMissingInRegularAndScriptAsync(code); } - [WpfFact] + [Fact] public async Task NoAction_MatchingNamespace_InGlobalNamespace() { var folders = Array.Empty(); @@ -246,7 +246,7 @@ class [||]Class1 await TestMissingInRegularAndScriptAsync(code); } - [WpfFact] + [Fact] public async Task NoAction_MatchingNamespace_DefaultGlobalNamespace() { var folders = new[] { "A", "B", "C" }; @@ -270,7 +270,7 @@ class Class1 await TestMissingInRegularAndScriptAsync(code); } - [WpfFact] + [Fact] public async Task NoAction_MatchingNamespace_InNamespaceDeclaration() { var folders = new[] { "B", "C" }; @@ -294,7 +294,7 @@ class Class1 await TestMissingInRegularAndScriptAsync(code); } - [WpfFact] + [Fact] public async Task NoAction_FileNotRooted() { var filePath = PathUtilities.CombineAbsoluteAndRelativePaths(PathUtilities.GetPathRoot(ProjectFilePath), "Foo.cs"); @@ -317,7 +317,7 @@ class Class1 await TestMissingInRegularAndScriptAsync(code); } - [WpfFact] + [Fact] public async Task NoAction_NoDeclaration() { var folders = new[] { "A" }; diff --git a/src/Features/VisualBasicTest/EncapsulateField/EncapsulateFieldTests.vb b/src/Features/VisualBasicTest/EncapsulateField/EncapsulateFieldTests.vb index 6103472a41778..c6512ef9a9573 100644 --- a/src/Features/VisualBasicTest/EncapsulateField/EncapsulateFieldTests.vb +++ b/src/Features/VisualBasicTest/EncapsulateField/EncapsulateFieldTests.vb @@ -347,7 +347,7 @@ End Class.ConvertTestSourceTag() }, testHost:=host) End Function - + Public Async Function TestEncapsulateFieldNamedValue(host As TestHost) As Task Dim text = Class C @@ -617,7 +617,7 @@ End Enum End Function - + Public Async Function ApplyCurrentMePrefixStyle(host As TestHost) As Task Await TestInRegularAndScriptAsync(" Class C diff --git a/src/Features/VisualBasicTest/GenerateVariable/GenerateVariableTests.vb b/src/Features/VisualBasicTest/GenerateVariable/GenerateVariableTests.vb index 97763c674186e..babb6aba59b1c 100644 --- a/src/Features/VisualBasicTest/GenerateVariable/GenerateVariableTests.vb +++ b/src/Features/VisualBasicTest/GenerateVariable/GenerateVariableTests.vb @@ -719,7 +719,7 @@ index:=1) End Function - + Public Async Function TestRefLambda() As Task Await TestInRegularAndScriptAsync( "Class [Class] diff --git a/src/Features/VisualBasicTest/ImplementInterface/ImplementInterfaceTests.vb b/src/Features/VisualBasicTest/ImplementInterface/ImplementInterfaceTests.vb index 0e3be0a29ed05..a318292553192 100644 --- a/src/Features/VisualBasicTest/ImplementInterface/ImplementInterfaceTests.vb +++ b/src/Features/VisualBasicTest/ImplementInterface/ImplementInterfaceTests.vb @@ -40,7 +40,7 @@ Class C End Class") End Function - + Public Async Function TestInterfaceWithTuple() As Task Await TestInRegularAndScriptAsync( "Imports System diff --git a/src/Features/VisualBasicTest/InlineTemporary/InlineTemporaryTests.vb b/src/Features/VisualBasicTest/InlineTemporary/InlineTemporaryTests.vb index 3932cb5a412c9..1ab9a0e796add 100644 --- a/src/Features/VisualBasicTest/InlineTemporary/InlineTemporaryTests.vb +++ b/src/Features/VisualBasicTest/InlineTemporary/InlineTemporaryTests.vb @@ -546,7 +546,7 @@ Console.Write(New String(" "c, 10).Length) - + Public Async Function TestInlineIntoMemberAccess4() As Task Dim code = diff --git a/src/Features/VisualBasicTest/IntroduceVariable/IntroduceVariableTests.vb b/src/Features/VisualBasicTest/IntroduceVariable/IntroduceVariableTests.vb index 6ab9db0494d08..b7fc7f20a9a4f 100644 --- a/src/Features/VisualBasicTest/IntroduceVariable/IntroduceVariableTests.vb +++ b/src/Features/VisualBasicTest/IntroduceVariable/IntroduceVariableTests.vb @@ -1705,7 +1705,7 @@ End Class End Function - + Public Async Function TestNoRefactoringOnAddressOfExpression() As Task Dim source = "Imports System Module Module1 diff --git a/src/Features/VisualBasicTest/InvertIf/InvertMultiLineIfTests.vb b/src/Features/VisualBasicTest/InvertIf/InvertMultiLineIfTests.vb index 24ebc542f8fd4..6a326d2ddb1c1 100644 --- a/src/Features/VisualBasicTest/InvertIf/InvertMultiLineIfTests.vb +++ b/src/Features/VisualBasicTest/InvertIf/InvertMultiLineIfTests.vb @@ -549,7 +549,7 @@ End Module") - + Public Async Function TestColonAfterSingleLineIfWithEmptyElse() As Task Await TestInRegularAndScriptAsync( "Module Program @@ -607,7 +607,7 @@ End Module") End Function - + Public Async Function TestDoNotRemoveTypeCharactersDuringComplexification() As Task Dim markup = diff --git a/src/Features/VisualBasicTest/InvertIf/InvertSingleLineIfTests.vb b/src/Features/VisualBasicTest/InvertIf/InvertSingleLineIfTests.vb index b65d67dafb4a3..71e697792fbf1 100644 --- a/src/Features/VisualBasicTest/InvertIf/InvertSingleLineIfTests.vb +++ b/src/Features/VisualBasicTest/InvertIf/InvertSingleLineIfTests.vb @@ -314,7 +314,7 @@ End Module End Function - + Public Async Function TestXor2() As Task Await TestFixOneAsync( " @@ -493,7 +493,7 @@ End Module") - + Public Async Function TestNestedSingleLineIfs() As Task Await TestInRegularAndScriptAsync( "Module Program @@ -537,7 +537,7 @@ End Module") End Function - + Public Async Function TestImplicitLineContinuationBeforeClosingParenIsRemoved() As Task Dim markup =