From 3691da454a16e626df68a8231243baabb62004a9 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 11 Nov 2020 17:29:33 -0800 Subject: [PATCH 1/3] Don't offer use-compound-assignment with implicit object creation. --- .../UseCompoundAssignmentTests.cs | 22 +++++++++++++++++-- .../Services/SyntaxFacts/CSharpSyntaxFacts.cs | 6 ++--- .../Core/Extensions/SyntaxNodeExtensions.cs | 3 +++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Analyzers/CSharp/Tests/UseCompoundAssignment/UseCompoundAssignmentTests.cs b/src/Analyzers/CSharp/Tests/UseCompoundAssignment/UseCompoundAssignmentTests.cs index b2a0c5b150024..02ab9b380b3c8 100644 --- a/src/Analyzers/CSharp/Tests/UseCompoundAssignment/UseCompoundAssignmentTests.cs +++ b/src/Analyzers/CSharp/Tests/UseCompoundAssignment/UseCompoundAssignmentTests.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp; @@ -790,6 +788,26 @@ InsertionPoint Up() }"); } + [WorkItem(49294, "https://github.com/dotnet/roslyn/issues/49294")] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseCompoundAssignment)] + public async Task TestNotOnImplicitObjectInitializer() + { + await TestMissingAsync( +@" +struct InsertionPoint +{ + int level; + + InsertionPoint Up() + { + return new() + { + level [||]= level - 1, + }; + } +}"); + } + [WorkItem(38137, "https://github.com/dotnet/roslyn/issues/38137")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseCompoundAssignment)] public async Task TestParenthesizedExpression() diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SyntaxFacts/CSharpSyntaxFacts.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SyntaxFacts/CSharpSyntaxFacts.cs index 1a419942eb87d..1a35d21dc5c5f 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SyntaxFacts/CSharpSyntaxFacts.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SyntaxFacts/CSharpSyntaxFacts.cs @@ -678,10 +678,10 @@ public bool IsObjectInitializerNamedAssignmentIdentifier( identifier.IsLeftSideOfAssignExpression() && identifier.Parent.IsParentKind(SyntaxKind.ObjectInitializerExpression)) { - var objectInitializer = identifier.Parent.Parent; - if (objectInitializer.IsParentKind(SyntaxKind.ObjectCreationExpression)) + var objectInitializer = identifier.Parent.GetRequiredParent(); + if (objectInitializer.Parent is BaseObjectCreationExpressionSyntax) { - initializedInstance = objectInitializer.Parent!; + initializedInstance = objectInitializer.Parent; return true; } else if (objectInitializer.IsParentKind(SyntaxKind.SimpleAssignmentExpression, out AssignmentExpressionSyntax? assignment)) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/SyntaxNodeExtensions.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/SyntaxNodeExtensions.cs index bc027756bb417..9c3274e0e2f6a 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/SyntaxNodeExtensions.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/SyntaxNodeExtensions.cs @@ -18,6 +18,9 @@ namespace Microsoft.CodeAnalysis.Shared.Extensions { internal static class SyntaxNodeExtensions { + public static SyntaxNode GetRequiredParent(this SyntaxNode node) + => node.Parent ?? throw new InvalidOperationException("Node's parent was null"); + public static IEnumerable DepthFirstTraversal(this SyntaxNode node) => SyntaxNodeOrTokenExtensions.DepthFirstTraversal(node); From 4cdd11262c442a9f1b4025fe6a994eb5e8fc4577 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 11 Nov 2020 17:56:11 -0800 Subject: [PATCH 2/3] Handle more cases --- .../UseCompoundAssignmentTests.cs | 18 ++++ ...UseCompoundAssignmentDiagnosticAnalyzer.cs | 6 +- .../ReplaceMethodWithPropertyTests.cs | 2 - .../ReplacePropertyWithMethodsTests.cs | 90 ++++++++++++++++++- .../GenerateVariable/GenerateVariableTests.cs | 32 ++++++- .../AbstractGenerateMemberService.cs | 2 +- .../AbstractGenerateVariableService.State.cs | 2 +- ...pertyWithMethodsCodeRefactoringProvider.cs | 2 +- .../Services/SyntaxFacts/CSharpSyntaxFacts.cs | 30 ++++--- .../Core/Services/SyntaxFacts/ISyntaxFacts.cs | 4 +- .../SyntaxFacts/VisualBasicSyntaxFacts.vb | 8 +- 11 files changed, 168 insertions(+), 28 deletions(-) diff --git a/src/Analyzers/CSharp/Tests/UseCompoundAssignment/UseCompoundAssignmentTests.cs b/src/Analyzers/CSharp/Tests/UseCompoundAssignment/UseCompoundAssignmentTests.cs index 02ab9b380b3c8..65769a72b907f 100644 --- a/src/Analyzers/CSharp/Tests/UseCompoundAssignment/UseCompoundAssignmentTests.cs +++ b/src/Analyzers/CSharp/Tests/UseCompoundAssignment/UseCompoundAssignmentTests.cs @@ -808,6 +808,24 @@ InsertionPoint Up() }"); } + [WorkItem(49294, "https://github.com/dotnet/roslyn/issues/49294")] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseCompoundAssignment)] + public async Task TestNotOnRecord() + { + await TestMissingAsync( +@" +record InsertionPoint(int level) +{ + InsertionPoint Up() + { + return this with + { + level [||]= level - 1, + }; + } +}"); + } + [WorkItem(38137, "https://github.com/dotnet/roslyn/issues/38137")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseCompoundAssignment)] public async Task TestParenthesizedExpression() diff --git a/src/Analyzers/Core/Analyzers/UseCompoundAssignment/AbstractUseCompoundAssignmentDiagnosticAnalyzer.cs b/src/Analyzers/Core/Analyzers/UseCompoundAssignment/AbstractUseCompoundAssignmentDiagnosticAnalyzer.cs index 4b01bb89e7a28..3d3d2ab4eab53 100644 --- a/src/Analyzers/Core/Analyzers/UseCompoundAssignment/AbstractUseCompoundAssignmentDiagnosticAnalyzer.cs +++ b/src/Analyzers/Core/Analyzers/UseCompoundAssignment/AbstractUseCompoundAssignmentDiagnosticAnalyzer.cs @@ -111,8 +111,10 @@ private void AnalyzeAssignment(SyntaxNodeAnalysisContext context) } // Don't offer if this is `x = x + 1` inside an obj initializer like: - // `new Point { x = x + 1 }` - if (_syntaxFacts.IsObjectInitializerNamedAssignmentIdentifier(assignmentLeft)) + // `new Point { x = x + 1 }` or + // `new () { x = x + 1 }` or + // `p with { x = x + 1 }` + if (_syntaxFacts.IsMemberInitializerNamedAssignmentIdentifier(assignmentLeft)) { return; } diff --git a/src/EditorFeatures/CSharpTest/CodeActions/ReplaceMethodWithProperty/ReplaceMethodWithPropertyTests.cs b/src/EditorFeatures/CSharpTest/CodeActions/ReplaceMethodWithProperty/ReplaceMethodWithPropertyTests.cs index 05b357bc4e284..2b4be9a7427ef 100644 --- a/src/EditorFeatures/CSharpTest/CodeActions/ReplaceMethodWithProperty/ReplaceMethodWithPropertyTests.cs +++ b/src/EditorFeatures/CSharpTest/CodeActions/ReplaceMethodWithProperty/ReplaceMethodWithPropertyTests.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeRefactorings; using Microsoft.CodeAnalysis.CSharp.CodeStyle; diff --git a/src/EditorFeatures/CSharpTest/CodeActions/ReplacePropertyWithMethods/ReplacePropertyWithMethodsTests.cs b/src/EditorFeatures/CSharpTest/CodeActions/ReplacePropertyWithMethods/ReplacePropertyWithMethodsTests.cs index e7867fdcd6ebf..38a90857c12f4 100644 --- a/src/EditorFeatures/CSharpTest/CodeActions/ReplacePropertyWithMethods/ReplacePropertyWithMethodsTests.cs +++ b/src/EditorFeatures/CSharpTest/CodeActions/ReplacePropertyWithMethods/ReplacePropertyWithMethodsTests.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeRefactorings; using Microsoft.CodeAnalysis.CSharp.CodeStyle; @@ -1889,6 +1887,94 @@ void Main() }"); } + [WorkItem(45171, "https://github.com/dotnet/roslyn/issues/45171")] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)] + public async Task TestReferenceInImplicitObjectInitializer() + { + await TestInRegularAndScriptAsync( +@"public class Tweet +{ + public string [||]Tweet { get; } +} + +class C +{ + void Main() + { + var t = new Tweet(); + Tweet t1 = new() + { + Tweet = t.Tweet + }; + } +}", +@"public class Tweet +{ + private readonly string tweet; + + public string GetTweet() + { + return tweet; + } +} + +class C +{ + void Main() + { + var t = new Tweet(); + Tweet t1 = new() + { + {|Conflict:Tweet|} = t.GetTweet() + }; + } +}"); + } + + [WorkItem(45171, "https://github.com/dotnet/roslyn/issues/45171")] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplacePropertyWithMethods)] + public async Task TestReferenceInWithInitializer() + { + await TestInRegularAndScriptAsync( +@"public class Tweet +{ + public string [||]Tweet { get; } +} + +class C +{ + void Main() + { + var t = new Tweet(); + var t1 = t with + { + Tweet = t.Tweet + }; + } +}", +@"public class Tweet +{ + private readonly string tweet; + + public string GetTweet() + { + return tweet; + } +} + +class C +{ + void Main() + { + var t = new Tweet(); + var t1 = t with + { + {|Conflict:Tweet|} = t.GetTweet() + }; + } +}"); + } + private OptionsCollection PreferExpressionBodiedMethods => new OptionsCollection(GetLanguage()) { { CSharpCodeStyleOptions.PreferExpressionBodiedMethods, CSharpCodeStyleOptions.WhenPossibleWithSuggestionEnforcement } }; } diff --git a/src/EditorFeatures/CSharpTest/GenerateVariable/GenerateVariableTests.cs b/src/EditorFeatures/CSharpTest/GenerateVariable/GenerateVariableTests.cs index 4a745489fd545..7c56104cd029d 100644 --- a/src/EditorFeatures/CSharpTest/GenerateVariable/GenerateVariableTests.cs +++ b/src/EditorFeatures/CSharpTest/GenerateVariable/GenerateVariableTests.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Collections.Generic; using System.Collections.Immutable; using System.Threading.Tasks; @@ -3515,6 +3513,36 @@ void goo() }"); } + [WorkItem(49294, "https://github.com/dotnet/roslyn/issues/49294")] + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateVariable)] + public async Task TestPropertyInWithInitializer() + { + await TestInRegularAndScriptAsync( +@"record Goo +{ +} + +class Bar +{ + void goo(Goo g) + { + var c = g with { [|Gibberish|] = 24 }; + } +}", +@"record Goo +{ + public int Gibberish { get; internal set; } +} + +class Bar +{ + void goo(Goo g) + { + var c = g with { Gibberish = 24 }; + } +}"); + } + [WorkItem(13166, "https://github.com/dotnet/roslyn/issues/13166")] [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateVariable)] public async Task TestPropertyOnNestedObjectInitializer() diff --git a/src/Features/Core/Portable/GenerateMember/AbstractGenerateMemberService.cs b/src/Features/Core/Portable/GenerateMember/AbstractGenerateMemberService.cs index 495a7e24cfb2c..e4fb57fbc600e 100644 --- a/src/Features/Core/Portable/GenerateMember/AbstractGenerateMemberService.cs +++ b/src/Features/Core/Portable/GenerateMember/AbstractGenerateMemberService.cs @@ -154,7 +154,7 @@ private static void TryDetermineTypeToGenerateInWorker( return; } - if (syntaxFacts.IsObjectInitializerNamedAssignmentIdentifier( + if (syntaxFacts.IsMemberInitializerNamedAssignmentIdentifier( expression, out var initializedObject)) { typeToGenerateIn = semanticModel.GetTypeInfo(initializedObject, cancellationToken).Type as INamedTypeSymbol; diff --git a/src/Features/Core/Portable/GenerateMember/GenerateVariable/AbstractGenerateVariableService.State.cs b/src/Features/Core/Portable/GenerateMember/GenerateVariable/AbstractGenerateVariableService.State.cs index e5d1ac53a5471..c7c76d9ae1d1f 100644 --- a/src/Features/Core/Portable/GenerateMember/GenerateVariable/AbstractGenerateVariableService.State.cs +++ b/src/Features/Core/Portable/GenerateMember/GenerateVariable/AbstractGenerateVariableService.State.cs @@ -276,7 +276,7 @@ private bool TryInitializeSimpleName( IsInConstructor = DetermineIsInConstructor(semanticDocument, simpleName); IsInMemberContext = simpleName != SimpleNameOrMemberAccessExpressionOpt || - syntaxFacts.IsObjectInitializerNamedAssignmentIdentifier(SimpleNameOrMemberAccessExpressionOpt); + syntaxFacts.IsMemberInitializerNamedAssignmentIdentifier(SimpleNameOrMemberAccessExpressionOpt); ContainingMethod = semanticModel.GetEnclosingSymbol(IdentifierToken.SpanStart, cancellationToken); diff --git a/src/Features/Core/Portable/ReplacePropertyWithMethods/ReplacePropertyWithMethodsCodeRefactoringProvider.cs b/src/Features/Core/Portable/ReplacePropertyWithMethods/ReplacePropertyWithMethodsCodeRefactoringProvider.cs index b7bc55e02dc4b..26ba3f8e13cc1 100644 --- a/src/Features/Core/Portable/ReplacePropertyWithMethods/ReplacePropertyWithMethodsCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/ReplacePropertyWithMethods/ReplacePropertyWithMethodsCodeRefactoringProvider.cs @@ -262,7 +262,7 @@ private static async Task ReplaceReferencesAsync( editor.ReplaceNode(parent, parent.WithAdditionalAnnotations( ConflictAnnotation.Create(FeaturesResources.Property_referenced_implicitly))); } - else if (syntaxFacts.IsObjectInitializerNamedAssignmentIdentifier(parent)) + else if (syntaxFacts.IsMemberInitializerNamedAssignmentIdentifier(parent)) { editor.ReplaceNode(parent, parent.WithAdditionalAnnotations( ConflictAnnotation.Create(FeaturesResources.Property_reference_cannot_be_updated))); diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SyntaxFacts/CSharpSyntaxFacts.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SyntaxFacts/CSharpSyntaxFacts.cs index 1a35d21dc5c5f..d6d0957424204 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SyntaxFacts/CSharpSyntaxFacts.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Services/SyntaxFacts/CSharpSyntaxFacts.cs @@ -667,27 +667,35 @@ public bool IsNameOfSubpattern([NotNullWhen(true)] SyntaxNode? node) public bool IsPropertyPatternClause(SyntaxNode node) => node.Kind() == SyntaxKind.PropertyPatternClause; - public bool IsObjectInitializerNamedAssignmentIdentifier([NotNullWhen(true)] SyntaxNode? node) - => IsObjectInitializerNamedAssignmentIdentifier(node, out _); + public bool IsMemberInitializerNamedAssignmentIdentifier([NotNullWhen(true)] SyntaxNode? node) + => IsMemberInitializerNamedAssignmentIdentifier(node, out _); - public bool IsObjectInitializerNamedAssignmentIdentifier( + public bool IsMemberInitializerNamedAssignmentIdentifier( [NotNullWhen(true)] SyntaxNode? node, [NotNullWhen(true)] out SyntaxNode? initializedInstance) { initializedInstance = null; if (node is IdentifierNameSyntax identifier && - identifier.IsLeftSideOfAssignExpression() && - identifier.Parent.IsParentKind(SyntaxKind.ObjectInitializerExpression)) + identifier.IsLeftSideOfAssignExpression()) { - var objectInitializer = identifier.Parent.GetRequiredParent(); - if (objectInitializer.Parent is BaseObjectCreationExpressionSyntax) + if (identifier.Parent.IsParentKind(SyntaxKind.WithInitializerExpression)) { - initializedInstance = objectInitializer.Parent; + var withInitializer = identifier.Parent.GetRequiredParent(); + initializedInstance = withInitializer.GetRequiredParent(); return true; } - else if (objectInitializer.IsParentKind(SyntaxKind.SimpleAssignmentExpression, out AssignmentExpressionSyntax? assignment)) + else if (identifier.Parent.IsParentKind(SyntaxKind.ObjectInitializerExpression)) { - initializedInstance = assignment.Left; - return true; + var objectInitializer = identifier.Parent.GetRequiredParent(); + if (objectInitializer.Parent is BaseObjectCreationExpressionSyntax) + { + initializedInstance = objectInitializer.Parent; + return true; + } + else if (objectInitializer.IsParentKind(SyntaxKind.SimpleAssignmentExpression, out AssignmentExpressionSyntax? assignment)) + { + initializedInstance = assignment.Left; + return true; + } } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Services/SyntaxFacts/ISyntaxFacts.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Services/SyntaxFacts/ISyntaxFacts.cs index 60df87d9ee826..1e79558e19ef6 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Services/SyntaxFacts/ISyntaxFacts.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Services/SyntaxFacts/ISyntaxFacts.cs @@ -275,8 +275,8 @@ void GetPartsOfTupleExpression(SyntaxNode node, SyntaxList GetAttributeLists(SyntaxNode? node); bool IsAttributeNamedArgumentIdentifier([NotNullWhen(true)] SyntaxNode? node); - bool IsObjectInitializerNamedAssignmentIdentifier([NotNullWhen(true)] SyntaxNode? node); - bool IsObjectInitializerNamedAssignmentIdentifier([NotNullWhen(true)] SyntaxNode? node, [NotNullWhen(true)] out SyntaxNode? initializedInstance); + bool IsMemberInitializerNamedAssignmentIdentifier([NotNullWhen(true)] SyntaxNode? node); + bool IsMemberInitializerNamedAssignmentIdentifier([NotNullWhen(true)] SyntaxNode? node, [NotNullWhen(true)] out SyntaxNode? initializedInstance); bool IsDirective([NotNullWhen(true)] SyntaxNode? node); bool IsStatement([NotNullWhen(true)] SyntaxNode? node); diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/VisualBasic/Services/SyntaxFacts/VisualBasicSyntaxFacts.vb b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/VisualBasic/Services/SyntaxFacts/VisualBasicSyntaxFacts.vb index f6501a78b3097..f90a13ee38095 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/VisualBasic/Services/SyntaxFacts/VisualBasicSyntaxFacts.vb +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/VisualBasic/Services/SyntaxFacts/VisualBasicSyntaxFacts.vb @@ -685,14 +685,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.LanguageServices Return node.FindTokenOnRightOfPosition(position, includeSkipped, includeDirectives, includeDocumentationComments) End Function - Public Function IsObjectInitializerNamedAssignmentIdentifier(node As SyntaxNode) As Boolean Implements ISyntaxFacts.IsObjectInitializerNamedAssignmentIdentifier + Public Function IsMemberInitializerNamedAssignmentIdentifier(node As SyntaxNode) As Boolean Implements ISyntaxFacts.IsMemberInitializerNamedAssignmentIdentifier Dim unused As SyntaxNode = Nothing - Return IsObjectInitializerNamedAssignmentIdentifier(node, unused) + Return IsMemberInitializerNamedAssignmentIdentifier(node, unused) End Function - Public Function IsObjectInitializerNamedAssignmentIdentifier( + Public Function IsMemberInitializerNamedAssignmentIdentifier( node As SyntaxNode, - ByRef initializedInstance As SyntaxNode) As Boolean Implements ISyntaxFacts.IsObjectInitializerNamedAssignmentIdentifier + ByRef initializedInstance As SyntaxNode) As Boolean Implements ISyntaxFacts.IsMemberInitializerNamedAssignmentIdentifier Dim identifier = TryCast(node, IdentifierNameSyntax) If identifier?.IsChildNode(Of NamedFieldInitializerSyntax)(Function(n) n.Name) Then From 0e03a265e5479f45b0e785378c3df512097a9b6c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 11 Nov 2020 18:45:44 -0800 Subject: [PATCH 3/3] nrt --- .../ReplaceMethodWithProperty/ReplaceMethodWithPropertyTests.cs | 2 +- .../CSharpTest/GenerateVariable/GenerateVariableTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/CodeActions/ReplaceMethodWithProperty/ReplaceMethodWithPropertyTests.cs b/src/EditorFeatures/CSharpTest/CodeActions/ReplaceMethodWithProperty/ReplaceMethodWithPropertyTests.cs index 2b4be9a7427ef..8aff66360e4c0 100644 --- a/src/EditorFeatures/CSharpTest/CodeActions/ReplaceMethodWithProperty/ReplaceMethodWithPropertyTests.cs +++ b/src/EditorFeatures/CSharpTest/CodeActions/ReplaceMethodWithProperty/ReplaceMethodWithPropertyTests.cs @@ -2413,7 +2413,7 @@ int Goo private async Task TestWithAllCodeStyleOff( string initialMarkup, string expectedMarkup, - ParseOptions parseOptions = null, int index = 0) + ParseOptions? parseOptions = null, int index = 0) { await TestAsync( initialMarkup, expectedMarkup, parseOptions, diff --git a/src/EditorFeatures/CSharpTest/GenerateVariable/GenerateVariableTests.cs b/src/EditorFeatures/CSharpTest/GenerateVariable/GenerateVariableTests.cs index 7c56104cd029d..f5a0a5770ae48 100644 --- a/src/EditorFeatures/CSharpTest/GenerateVariable/GenerateVariableTests.cs +++ b/src/EditorFeatures/CSharpTest/GenerateVariable/GenerateVariableTests.cs @@ -36,7 +36,7 @@ public GenerateVariableTests(ITestOutputHelper logger) { } - internal override (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace) + internal override (DiagnosticAnalyzer?, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace) => (null, new CSharpGenerateVariableCodeFixProvider()); private readonly CodeStyleOption2 onWithInfo = new CodeStyleOption2(true, NotificationOption2.Suggestion);