diff --git a/src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolution.cs b/src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolution.cs index 5acde0dfa8f0a..532a02f8712b6 100644 --- a/src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolution.cs +++ b/src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolution.cs @@ -2767,6 +2767,16 @@ private BetterResult BetterConversionFromExpression(BoundExpression node, TypeSy return BetterResult.Neither; } + switch ((conv1.Kind, conv2.Kind)) + { + case (ConversionKind.ImplicitSpan, ConversionKind.ImplicitSpan): + break; + case (_, ConversionKind.ImplicitSpan): + return BetterResult.Right; + case (ConversionKind.ImplicitSpan, _): + return BetterResult.Left; + } + // - T1 is a better conversion target than T2 and either C1 and C2 are both conditional expression // conversions or neither is a conditional expression conversion. return BetterConversionTarget(node, t1, conv1, t2, conv2, ref useSiteInfo, out okToDowngradeToNeither); diff --git a/src/Compilers/CSharp/Test/Emit2/Diagnostics/DiagnosticAnalyzerTests.AllInOne.cs b/src/Compilers/CSharp/Test/Emit2/Diagnostics/DiagnosticAnalyzerTests.AllInOne.cs index 56db7fd8ba725..6faa5984d11a6 100644 --- a/src/Compilers/CSharp/Test/Emit2/Diagnostics/DiagnosticAnalyzerTests.AllInOne.cs +++ b/src/Compilers/CSharp/Test/Emit2/Diagnostics/DiagnosticAnalyzerTests.AllInOne.cs @@ -38,7 +38,7 @@ public void DiagnosticAnalyzerAllInOne() missingSyntaxKinds.Add(SyntaxKind.SpreadElement); var analyzer = new CSharpTrackingDiagnosticAnalyzer(); - var options = new AnalyzerOptions([new TestAdditionalText()]); + var options = new AnalyzerOptions(new[] { new TestAdditionalText() }.ToImmutableArray()); CreateCompilationWithMscorlib45(source).VerifyAnalyzerDiagnostics(new[] { analyzer }, options); analyzer.VerifyAllAnalyzerMembersWereCalled(); analyzer.VerifyAnalyzeSymbolCalledForAllSymbolKinds(); @@ -99,7 +99,7 @@ public class C public void AnalyzerDriverIsSafeAgainstAnalyzerExceptions() { var compilation = CreateCompilationWithMscorlib45(TestResource.AllInOneCSharpCode); - var options = new AnalyzerOptions([new TestAdditionalText()]); + var options = new AnalyzerOptions(new[] { new TestAdditionalText() }.ToImmutableArray()); ThrowingDiagnosticAnalyzer.VerifyAnalyzerEngineIsSafeAgainstExceptions(analyzer => compilation.GetAnalyzerDiagnostics(new[] { analyzer }, options)); @@ -111,7 +111,7 @@ public void AnalyzerOptionsArePassedToAllAnalyzers() var text = new StringText(string.Empty, encodingOpt: null); AnalyzerOptions options = new AnalyzerOptions ( - [new TestAdditionalText("myfilepath", text)] + new[] { new TestAdditionalText("myfilepath", text) }.ToImmutableArray() ); var compilation = CreateCompilationWithMscorlib45(TestResource.AllInOneCSharpCode); diff --git a/src/Compilers/CSharp/Test/Emit2/Semantics/CollectionExpressionTests.cs b/src/Compilers/CSharp/Test/Emit2/Semantics/CollectionExpressionTests.cs index 2ed198808f074..02c96b61d7f3f 100644 --- a/src/Compilers/CSharp/Test/Emit2/Semantics/CollectionExpressionTests.cs +++ b/src/Compilers/CSharp/Test/Emit2/Semantics/CollectionExpressionTests.cs @@ -1576,6 +1576,7 @@ static void Main() """; comp = CreateCompilation( new[] { sourceA, sourceB2 }, + parseOptions: TestOptions.Regular12, targetFramework: TargetFramework.Net80); comp.VerifyEmitDiagnostics( // 1.cs(5,9): error CS0121: The call is ambiguous between the following methods or properties: 'Program.SpanDerived(Span)' and 'Program.SpanDerived(object[])' @@ -1584,6 +1585,24 @@ static void Main() // 1.cs(6,9): error CS0121: The call is ambiguous between the following methods or properties: 'Program.ArrayDerived(Span)' and 'Program.ArrayDerived(string[])' // ArrayDerived([string.Empty]); // ambiguous Diagnostic(ErrorCode.ERR_AmbigCall, "ArrayDerived").WithArguments("Program.ArrayDerived(System.Span)", "Program.ArrayDerived(string[])").WithLocation(6, 9)); + + var expectedDiagnostics = new[] + { + // 1.cs(6,9): error CS0121: The call is ambiguous between the following methods or properties: 'Program.ArrayDerived(Span)' and 'Program.ArrayDerived(string[])' + // ArrayDerived([string.Empty]); // ambiguous + Diagnostic(ErrorCode.ERR_AmbigCall, "ArrayDerived").WithArguments("Program.ArrayDerived(System.Span)", "Program.ArrayDerived(string[])").WithLocation(6, 9) + }; + + comp = CreateCompilation( + new[] { sourceA, sourceB2 }, + parseOptions: TestOptions.RegularNext, + targetFramework: TargetFramework.Net80); + comp.VerifyEmitDiagnostics(expectedDiagnostics); + + comp = CreateCompilation( + new[] { sourceA, sourceB2 }, + targetFramework: TargetFramework.Net80); + comp.VerifyEmitDiagnostics(expectedDiagnostics); } [WorkItem("https://github.com/dotnet/roslyn/issues/69634")] diff --git a/src/Compilers/CSharp/Test/Emit2/Semantics/PatternMatchingTests_Scope.cs b/src/Compilers/CSharp/Test/Emit2/Semantics/PatternMatchingTests_Scope.cs index e82d618649ff1..91a7947e41648 100644 --- a/src/Compilers/CSharp/Test/Emit2/Semantics/PatternMatchingTests_Scope.cs +++ b/src/Compilers/CSharp/Test/Emit2/Semantics/PatternMatchingTests_Scope.cs @@ -12,7 +12,6 @@ using Microsoft.CodeAnalysis.CSharp.Test.Utilities; using Microsoft.CodeAnalysis.Test.Utilities; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.CSharp.UnitTests diff --git a/src/Compilers/CSharp/Test/Emit3/FirstClassSpanTests.cs b/src/Compilers/CSharp/Test/Emit3/FirstClassSpanTests.cs index 1719aad335ee1..90348dd6bf30e 100644 --- a/src/Compilers/CSharp/Test/Emit3/FirstClassSpanTests.cs +++ b/src/Compilers/CSharp/Test/Emit3/FirstClassSpanTests.cs @@ -193,15 +193,13 @@ static class E var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular12); CompileAndVerify(comp, expectedOutput: "2").VerifyDiagnostics(); - var expectedDiagnostics = new[] - { - // (5,5): error CS0121: The call is ambiguous between the following methods or properties: 'E.M(Span, T)' and 'E.M(IEnumerable, T)' - // arr.M('/'); - Diagnostic(ErrorCode.ERR_AmbigCall, "M").WithArguments("E.M(System.Span, T)", "E.M(System.Collections.Generic.IEnumerable, T)").WithLocation(5, 5) - }; + var expectedOutput = "1"; - CreateCompilationWithSpan(source, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(expectedDiagnostics); - CreateCompilationWithSpan(source).VerifyDiagnostics(expectedDiagnostics); + comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.RegularNext); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); + + comp = CreateCompilationWithSpan(source); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); } [Theory, MemberData(nameof(LangVersions))] @@ -261,11 +259,13 @@ static class E var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular12); CompileAndVerify(comp, expectedOutput: "2").VerifyDiagnostics(); + // PROTOTYPE: Can we avoid this break? + var expectedDiagnostics = new[] { - // (5,5): error CS0121: The call is ambiguous between the following methods or properties: 'E.M(Span, T)' and 'E.M(IEnumerable, T)' + // (5,5): error CS1113: Extension method 'E.M(Span, int)' defined on value type 'Span' cannot be used to create delegates // E.R(arr.M); - Diagnostic(ErrorCode.ERR_AmbigCall, "arr.M").WithArguments("E.M(System.Span, T)", "E.M(System.Collections.Generic.IEnumerable, T)").WithLocation(5, 5) + Diagnostic(ErrorCode.ERR_ValueTypeExtDelegate, "arr.M").WithArguments("E.M(System.Span, int)", "System.Span").WithLocation(5, 5) }; CreateCompilationWithSpan(source, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(expectedDiagnostics); @@ -2345,6 +2345,87 @@ .locals init (object[] V_0) verifier.VerifyIL("C.M", expectedIl); } + [Fact] + public void OverloadResolution_SpanVsIEnumerable() + { + var source = """ + using System; + using System.Collections.Generic; + + var a = new int[0]; + C.M(a); + + static class C + { + public static void M(Span x) => Console.Write(1); + public static void M(IEnumerable x) => Console.Write(2); + } + """; + + CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular12).VerifyDiagnostics( + // (5,3): error CS0121: The call is ambiguous between the following methods or properties: 'C.M(Span)' and 'C.M(IEnumerable)' + // C.M(a); + Diagnostic(ErrorCode.ERR_AmbigCall, "M").WithArguments("C.M(System.Span)", "C.M(System.Collections.Generic.IEnumerable)").WithLocation(5, 3)); + + var expectedOutput = "1"; + + var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.RegularNext); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); + + comp = CreateCompilationWithSpan(source); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); + } + + [Theory, MemberData(nameof(LangVersions))] + public void OverloadResolution_SpanVsIEnumerable_CollectionExpression(LanguageVersion langVersion) + { + var source = """ + using System; + using System.Collections.Generic; + + C.M([]); + + static class C + { + public static void M(Span x) => Console.Write(1); + public static void M(IEnumerable x) => Console.Write(2); + } + """; + var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); + CompileAndVerify(comp, expectedOutput: "1").VerifyDiagnostics(); + } + + [Fact] + public void OverloadResolution_SpanVsIEnumerable_Ctor() + { + var source = """ + using System; + using System.Collections.Generic; + + var a = new int[0]; + var c = new C(a); + + class C + { + public C(Span x) => Console.Write(1); + public C(IEnumerable x) => Console.Write(2); + } + """; + + CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular12).VerifyDiagnostics( + // (5,13): error CS0121: The call is ambiguous between the following methods or properties: 'C.C(Span)' and 'C.C(IEnumerable)' + // var c = new C(a); + Diagnostic(ErrorCode.ERR_AmbigCall, "C").WithArguments("C.C(System.Span)", "C.C(System.Collections.Generic.IEnumerable)").WithLocation(5, 13)); + + var expectedOutput = "1"; + + var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.RegularNext); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); + + comp = CreateCompilationWithSpan(source); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); + } + [Theory, MemberData(nameof(LangVersions))] public void OverloadResolution_ReadOnlySpanVsArray_01(LanguageVersion langVersion) { @@ -2391,8 +2472,8 @@ public static void M(ReadOnlySpan x) { } Diagnostic(ErrorCode.ERR_AmbigCall, "M").WithArguments("C.M(string[])", "C.M(System.ReadOnlySpan)").WithLocation(5, 3)); } - [Theory, MemberData(nameof(LangVersions))] - public void OverloadResolution_ReadOnlySpanVsArray_03(LanguageVersion langVersion) + [Fact] + public void OverloadResolution_ReadOnlySpanVsArray_03() { var source = """ using System; @@ -2410,8 +2491,16 @@ static class C public static void M(ReadOnlySpan x) => Console.Write(" r" + x[0]); } """; - var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); + var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular12); CompileAndVerify(comp, expectedOutput: "aa rSystem.String[] ra ra ra").VerifyDiagnostics(); + + var expectedOutput = "ra rSystem.String[] ra ra ra"; + + comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.RegularNext); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); + + comp = CreateCompilationWithSpan(source); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); } [Theory, MemberData(nameof(LangVersions))] @@ -2504,7 +2593,7 @@ static class C } """; var comp = CreateCompilationWithSpan(source); - CompileAndVerify(comp, expectedOutput: "aa rSystem.String[] ra ra ra").VerifyDiagnostics(); + CompileAndVerify(comp, expectedOutput: "ra rSystem.String[] ra ra ra").VerifyDiagnostics(); } [Fact] @@ -2566,21 +2655,17 @@ static class C var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular12); CompileAndVerify(comp, expectedOutput: "oa").VerifyDiagnostics(); - // PROTOTYPE: This break should go away with betterness rule. + var expectedOutput = "sa"; - var expectedDiagnostics = new[] - { - // (4,3): error CS0121: The call is ambiguous between the following methods or properties: 'C.M(object[])' and 'C.M(ReadOnlySpan)' - // a.M(); - Diagnostic(ErrorCode.ERR_AmbigCall, "M").WithArguments("C.M(object[])", "C.M(System.ReadOnlySpan)").WithLocation(4, 3) - }; + comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.RegularNext); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); - CreateCompilationWithSpan(source, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(expectedDiagnostics); - CreateCompilationWithSpan(source).VerifyDiagnostics(expectedDiagnostics); + comp = CreateCompilationWithSpan(source); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); } - [Theory, MemberData(nameof(LangVersions))] - public void OverloadResolution_ReadOnlySpanVsArray_ExtensionMethodReceiver_03(LanguageVersion langVersion) + [Fact] + public void OverloadResolution_ReadOnlySpanVsArray_ExtensionMethodReceiver_03() { var source = """ using System; @@ -2594,8 +2679,16 @@ static class C public static void M(this ReadOnlySpan x) => Console.Write(" r" + x[0]); } """; - var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); + var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular12); CompileAndVerify(comp, expectedOutput: "aa").VerifyDiagnostics(); + + var expectedOutput = "ra"; + + comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.RegularNext); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); + + comp = CreateCompilationWithSpan(source); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); } [Theory, MemberData(nameof(LangVersions))] @@ -2637,8 +2730,8 @@ static class C CompileAndVerify(comp, expectedOutput: "112").VerifyDiagnostics(); } - [Theory, MemberData(nameof(LangVersions))] - public void OverloadResolution_SpanVsReadOnlySpan_02(LanguageVersion langVersion) + [Fact] + public void OverloadResolution_SpanVsReadOnlySpan_02() { var source = """ using System; @@ -2655,8 +2748,16 @@ static class C public static void M(ReadOnlySpan arg) => Console.Write(2); } """; - var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); + var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular12); CompileAndVerify(comp, expectedOutput: "1121").VerifyDiagnostics(); + + var expectedOutput = "1122"; + + comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.RegularNext); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); + + comp = CreateCompilationWithSpan(source); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); } [Theory, MemberData(nameof(LangVersions))] @@ -2788,8 +2889,8 @@ public static void E(this ReadOnlySpan arg) { } // PROTOTYPE: Should work in C# 13 when ROS->ROS conversion is implemented. } - [Theory, MemberData(nameof(LangVersions))] - public void OverloadResolution_ReadOnlySpanVsArrayVsSpan(LanguageVersion langVersion) + [Fact] + public void OverloadResolution_ReadOnlySpanVsArrayVsSpan() { var source = """ using System; @@ -2817,8 +2918,16 @@ static class C public static void M(IEnumerable x) => Console.Write(" e" + x.First()); } """; - var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); + var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular12); CompileAndVerify(comp, expectedOutput: "aa rSystem.String[] ra ra ra ab rSystem.Object[] rb rb").VerifyDiagnostics(); + + var expectedOutput = "ra rSystem.String[] ra ra ra ab rSystem.Object[] rb rb"; + + comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.RegularNext); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); + + comp = CreateCompilationWithSpan(source); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); } [Fact] @@ -2851,11 +2960,11 @@ static class C } """; var comp = CreateCompilationWithSpan(source); - CompileAndVerify(comp, expectedOutput: "aa rSystem.String[] ra ra ra ab rSystem.Object[] rb rb").VerifyDiagnostics(); + CompileAndVerify(comp, expectedOutput: "ra rSystem.String[] ra ra ra ab rSystem.Object[] rb rb").VerifyDiagnostics(); } - [Theory, MemberData(nameof(LangVersions))] - public void OverloadResolution_ReadOnlySpanVsArrayVsSpan_ExtensionMethodReceiver(LanguageVersion langVersion) + [Fact] + public void OverloadResolution_ReadOnlySpanVsArrayVsSpan_ExtensionMethodReceiver() { var source = """ using System; @@ -2876,7 +2985,15 @@ static class C public static void M(this IEnumerable x) => Console.Write(" e" + x.First()); } """; - var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); + var comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.Regular12); CompileAndVerify(comp, expectedOutput: "aa ab").VerifyDiagnostics(); + + var expectedOutput = "ra ab"; + + comp = CreateCompilationWithSpan(source, parseOptions: TestOptions.RegularNext); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); + + comp = CreateCompilationWithSpan(source); + CompileAndVerify(comp, expectedOutput: expectedOutput).VerifyDiagnostics(); } } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/LookupPositionTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/LookupPositionTests.cs index 405335091954b..948e31354dbfb 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/LookupPositionTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/LookupPositionTests.cs @@ -12,7 +12,6 @@ using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.Test.Utilities; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.CSharp.UnitTests diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/VarianceTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/VarianceTests.cs index e41eb24d079b8..482521de337d1 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/VarianceTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/VarianceTests.cs @@ -11,7 +11,6 @@ using Microsoft.CodeAnalysis.CSharp.Test.Utilities; using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.CSharp.UnitTests diff --git a/src/Compilers/Core/CodeAnalysisTest/Collections/ImmutableSegmentedListTest.cs b/src/Compilers/Core/CodeAnalysisTest/Collections/ImmutableSegmentedListTest.cs index b153618443d3e..cdf5eca352f17 100644 --- a/src/Compilers/Core/CodeAnalysisTest/Collections/ImmutableSegmentedListTest.cs +++ b/src/Compilers/Core/CodeAnalysisTest/Collections/ImmutableSegmentedListTest.cs @@ -361,7 +361,9 @@ public void RemoveTest() Assert.False(list.Contains(10)); var removeList = new int[] { 20, 70 }; - list = list.RemoveAll(removeList.Contains); + // PROTOTYPE: Can we make the commented line work in bootstrap builds? + // list = list.RemoveAll(removeList.Contains); + list = list.RemoveAll(x => Array.IndexOf(removeList, x) >= 0); Assert.Equal(5, list.Count); Assert.False(list.Contains(20)); Assert.False(list.Contains(70)); @@ -384,7 +386,9 @@ public void RemoveTest() Assert.Equal(7, list2.Count); Assert.False(list2.Contains(10)); - list2 = list2.RemoveAll(removeList.Contains); + // PROTOTYPE: Can we make the commented line work in bootstrap builds? + // list2 = list2.RemoveAll(removeList.Contains); + list2 = list2.RemoveAll(x => Array.IndexOf(removeList, x) >= 0); Assert.Equal(5, list2.Count); Assert.False(list2.Contains(20)); Assert.False(list2.Contains(70)); diff --git a/src/Compilers/Core/CodeAnalysisTest/Diagnostics/AnalysisContextInfoTests.cs b/src/Compilers/Core/CodeAnalysisTest/Diagnostics/AnalysisContextInfoTests.cs index 499fb1450ecd1..d45da70ac553b 100644 --- a/src/Compilers/Core/CodeAnalysisTest/Diagnostics/AnalysisContextInfoTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/Diagnostics/AnalysisContextInfoTests.cs @@ -26,7 +26,7 @@ public void InitializeTest() var parseOptions = new CSharpParseOptions(kind: SourceCodeKind.Regular, documentationMode: DocumentationMode.None) .WithFeatures(new[] { new KeyValuePair("IOperation", "true") }); var compilation = CreateCompilation(code, parseOptions: parseOptions); - var options = new AnalyzerOptions([new TestAdditionalText()]); + var options = new AnalyzerOptions(new[] { new TestAdditionalText() }.ToImmutableArray()); Verify(compilation, options, nameof(AnalysisContext.RegisterCodeBlockAction)); Verify(compilation, options, nameof(AnalysisContext.RegisterCodeBlockStartAction)); diff --git a/src/Compilers/Core/Portable/InternalUtilities/ArrayExtensions.cs b/src/Compilers/Core/Portable/InternalUtilities/ArrayExtensions.cs index 4f1b9628f71a3..9078c540e2db3 100644 --- a/src/Compilers/Core/Portable/InternalUtilities/ArrayExtensions.cs +++ b/src/Compilers/Core/Portable/InternalUtilities/ArrayExtensions.cs @@ -26,12 +26,6 @@ internal static T[] Copy(this T[] array, int start, int length) return newArray; } - public static int IndexOf(this T[] array, T value) - => Array.IndexOf(array, value); - - public static bool Contains(this T[] array, T value) - => Array.IndexOf(array, value) >= 0; - internal static T[] InsertAt(this T[] array, int position, T item) { T[] newArray = new T[array.Length + 1]; diff --git a/src/Compilers/Test/Core/TargetFrameworkUtil.cs b/src/Compilers/Test/Core/TargetFrameworkUtil.cs index 00623f30f4e02..592cdb613b90f 100644 --- a/src/Compilers/Test/Core/TargetFrameworkUtil.cs +++ b/src/Compilers/Test/Core/TargetFrameworkUtil.cs @@ -18,7 +18,6 @@ using Microsoft.CodeAnalysis.CodeGen; using System.Reflection; using System.Collections.Concurrent; -using Roslyn.Utilities; namespace Roslyn.Test.Utilities { diff --git a/src/Features/LanguageServer/Protocol/Handler/Hover/ILspHoverResultCreationService.cs b/src/Features/LanguageServer/Protocol/Handler/Hover/ILspHoverResultCreationService.cs index 8928dcabe76d2..10e0d8e5c2726 100644 --- a/src/Features/LanguageServer/Protocol/Handler/Hover/ILspHoverResultCreationService.cs +++ b/src/Features/LanguageServer/Protocol/Handler/Hover/ILspHoverResultCreationService.cs @@ -12,7 +12,6 @@ using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.QuickInfo; using Roslyn.LanguageServer.Protocol; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.LanguageServer.Handler { diff --git a/src/Tools/GenerateRulesMissingDocumentation/Program.cs b/src/Tools/GenerateRulesMissingDocumentation/Program.cs index c8ed19cf4cde5..523cd91509a54 100644 --- a/src/Tools/GenerateRulesMissingDocumentation/Program.cs +++ b/src/Tools/GenerateRulesMissingDocumentation/Program.cs @@ -81,7 +81,7 @@ await checkHelpLinkAsync(helpLinkUri).ConfigureAwait(false)) { // We consider having "extra" entries as valid. This is to prevent CI failures due to rules being documented. // However, we consider "missing" entries as invalid. This is to force updating the file when new rules are added. - if (Array.IndexOf(actualContent, line) < 0) + if (!actualContent.Contains(line)) { await Console.Error.WriteLineAsync($"Missing entry in '{fileWithPath}'. Please add the below entry to this file to fix the build:").ConfigureAwait(false); await Console.Error.WriteLineAsync(line).ConfigureAwait(false); diff --git a/src/Workspaces/Core/Portable/CodeRefactorings/ExportCodeRefactoringProviderAttribute.cs b/src/Workspaces/Core/Portable/CodeRefactorings/ExportCodeRefactoringProviderAttribute.cs index b7dc5662aef4f..ccc282edc2fb3 100644 --- a/src/Workspaces/Core/Portable/CodeRefactorings/ExportCodeRefactoringProviderAttribute.cs +++ b/src/Workspaces/Core/Portable/CodeRefactorings/ExportCodeRefactoringProviderAttribute.cs @@ -6,7 +6,6 @@ using System.Composition; using System.Diagnostics.CodeAnalysis; using System.Linq; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CodeRefactorings; diff --git a/src/Workspaces/Core/Portable/Workspace/Host/Mef/MefHostServices.cs b/src/Workspaces/Core/Portable/Workspace/Host/Mef/MefHostServices.cs index 3f0e3532e99d7..9078fc1ef6412 100644 --- a/src/Workspaces/Core/Portable/Workspace/Host/Mef/MefHostServices.cs +++ b/src/Workspaces/Core/Portable/Workspace/Host/Mef/MefHostServices.cs @@ -12,7 +12,6 @@ using System.Linq; using System.Reflection; using System.Threading; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Host.Mef; diff --git a/src/Workspaces/MSBuildTest/NewlyCreatedProjectsFromDotNetNew.cs b/src/Workspaces/MSBuildTest/NewlyCreatedProjectsFromDotNetNew.cs index ca70ed81a0f02..f403ed97cfc89 100644 --- a/src/Workspaces/MSBuildTest/NewlyCreatedProjectsFromDotNetNew.cs +++ b/src/Workspaces/MSBuildTest/NewlyCreatedProjectsFromDotNetNew.cs @@ -11,7 +11,6 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis.Shared.Extensions; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; using Xunit.Abstractions; diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ArrayExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ArrayExtensions.cs index 6dddc2904ceff..ddee284eecaba 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ArrayExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/ArrayExtensions.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using System.Diagnostics.CodeAnalysis; namespace Microsoft.CodeAnalysis.Shared.Extensions; @@ -10,4 +11,7 @@ internal static class ArrayExtensions { public static bool IsNullOrEmpty([NotNullWhen(returnValue: false)] this T[]? array) => array == null || array.Length == 0; + + public static bool Contains(this T[] array, T item) + => Array.IndexOf(array, item) >= 0; }