Skip to content

Commit

Permalink
Merge pull request #53666 from dotnet/merges/main-to-main-vs-deps
Browse files Browse the repository at this point in the history
Merge main to main-vs-deps
  • Loading branch information
msftbot[bot] authored May 25, 2021
2 parents a776edd + f04d51c commit 6967597
Show file tree
Hide file tree
Showing 128 changed files with 2,849 additions and 484 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ private void ProcessMemberDeclaration(
// If we have a class or struct, recurse inwards.
if (member.IsKind(SyntaxKind.ClassDeclaration, out TypeDeclarationSyntax typeDeclaration) ||
member.IsKind(SyntaxKind.StructDeclaration, out typeDeclaration) ||
member.IsKind(SyntaxKind.RecordDeclaration, out typeDeclaration))
member.IsKind(SyntaxKind.RecordDeclaration, out typeDeclaration) ||
member.IsKind(SyntaxKind.RecordStructDeclaration, out typeDeclaration))
{
ProcessMembers(context, option, typeDeclaration.Members);
}
Expand Down Expand Up @@ -116,6 +117,7 @@ private void ProcessMemberDeclaration(
case SyntaxKind.ClassDeclaration:
case SyntaxKind.RecordDeclaration:
case SyntaxKind.StructDeclaration:
case SyntaxKind.RecordStructDeclaration:
{
// Inside a type, default is private
if (accessibility != Accessibility.Private)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// 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.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.CSharp.CodeStyle;
using Microsoft.CodeAnalysis.CSharp.Syntax;
Expand All @@ -13,7 +12,7 @@
namespace Microsoft.CodeAnalysis.CSharp.MakeLocalFunctionStatic
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
internal class MakeLocalFunctionStaticDiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer
internal sealed class MakeLocalFunctionStaticDiagnosticAnalyzer : AbstractBuiltInCodeStyleDiagnosticAnalyzer
{
public MakeLocalFunctionStaticDiagnosticAnalyzer()
: base(IDEDiagnosticIds.MakeLocalFunctionStaticDiagnosticId,
Expand All @@ -29,7 +28,14 @@ public override DiagnosticAnalyzerCategory GetAnalyzerCategory()
=> DiagnosticAnalyzerCategory.SemanticSpanAnalysis;

protected override void InitializeWorker(AnalysisContext context)
=> context.RegisterSyntaxNodeAction(AnalyzeSyntax, SyntaxKind.LocalFunctionStatement);
=> context.RegisterCompilationStartAction(context =>
{
// All trees are expected to have the same language version. So make the check only once in compilation start .
if (context.Compilation.SyntaxTrees.FirstOrDefault() is SyntaxTree tree && MakeLocalFunctionStaticHelper.IsStaticLocalFunctionSupported(tree))
{
context.RegisterSyntaxNodeAction(AnalyzeSyntax, SyntaxKind.LocalFunctionStatement);
}
});

private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
{
Expand All @@ -40,11 +46,6 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
}

var syntaxTree = context.Node.SyntaxTree;
if (!MakeLocalFunctionStaticHelper.IsStaticLocalFunctionSupported(syntaxTree))
{
return;
}

var cancellationToken = context.CancellationToken;
var option = context.Options.GetOption(CSharpCodeStyleOptions.PreferStaticLocalFunction, syntaxTree, cancellationToken);
if (!option.Value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private static bool CanReplaceAnonymousWithLocalFunction(
if (identifierName.Identifier.ValueText == local.Name &&
local.Equals(semanticModel.GetSymbolInfo(identifierName, cancellationToken).GetAnySymbol()))
{
if (identifierName.IsWrittenTo())
if (identifierName.IsWrittenTo(semanticModel, cancellationToken))
{
// Can't change this to a local function if it is assigned to.
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private void SyntaxNodeAction(SyntaxNodeAnalysisContext syntaxContext)
// Check if this is a 'write' to the asOperand.
if (identifierName.Identifier.ValueText == asOperand?.Name &&
asOperand.Equals(semanticModel.GetSymbolInfo(identifierName, cancellationToken).Symbol) &&
identifierName.IsWrittenTo())
identifierName.IsWrittenTo(semanticModel, cancellationToken))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,32 @@ public sealed class IsExternalInit
await test.RunAsync();
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddAccessibilityModifiers)]
public async Task TestRecordStructs()
{
var source = @"
record struct [|Record|]
{
int [|field|];
}
";
var fixedSource = @"
internal record struct Record
{
private int field;
}
";

var test = new VerifyCS.Test
{
TestCode = source,
FixedCode = fixedSource,
LanguageVersion = CodeAnalysis.CSharp.LanguageVersion.Preview,
};

await test.RunAsync();
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddAccessibilityModifiers)]
public async Task TestReadOnlyStructs()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Syntax/SyntaxKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public enum SyntaxKind : ushort
/// <summary>Represents <see langword="not"/>.</summary>
NotKeyword = 8440,

// 8441 open for future use.
// Don't use 8441. It corresponds to a deleted kind (DataKeyword) that was previously shipped.

/// <summary>Represents <see langword="with"/>.</summary>
WithKeyword = 8442,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.Editor.Implementation.Formatting;
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.Editor.UnitTests.Utilities;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Formatting;
Expand All @@ -34,7 +33,7 @@ private static Dictionary<OptionKey2, object> SmartIndentButDoNotFormatWhileTypi
return new Dictionary<OptionKey2, object>
{
{ new OptionKey2(FormattingOptions2.SmartIndent, LanguageNames.CSharp), FormattingOptions.IndentStyle.Smart },
{ new OptionKey2(FeatureOnOffOptions.AutoFormattingOnTyping, LanguageNames.CSharp), false },
{ new OptionKey2(FormattingOptions2.AutoFormattingOnTyping, LanguageNames.CSharp), false },
{ new OptionKey2(BraceCompletionOptions.AutoFormattingOnCloseBrace, LanguageNames.CSharp), false },
};
}
Expand Down Expand Up @@ -1235,7 +1234,7 @@ class C

var optionSet = new Dictionary<OptionKey2, object>
{
{ new OptionKey2(FeatureOnOffOptions.AutoFormattingOnTyping, LanguageNames.CSharp), false }
{ new OptionKey2(FormattingOptions2.AutoFormattingOnTyping, LanguageNames.CSharp), false }
};

AssertFormatAfterTypeChar(code, expected, optionSet);
Expand Down Expand Up @@ -1267,7 +1266,7 @@ static void Main()

var optionSet = new Dictionary<OptionKey2, object>
{
{ new OptionKey2(FeatureOnOffOptions.AutoFormattingOnTyping, LanguageNames.CSharp), false }
{ new OptionKey2(FormattingOptions2.AutoFormattingOnTyping, LanguageNames.CSharp), false }
};

AssertFormatAfterTypeChar(code, expected, optionSet);
Expand Down Expand Up @@ -1325,7 +1324,7 @@ class C

var optionSet = new Dictionary<OptionKey2, object>
{
{ new OptionKey2(FeatureOnOffOptions.AutoFormattingOnSemicolon, LanguageNames.CSharp), false }
{ new OptionKey2(FormattingOptions2.AutoFormattingOnSemicolon, LanguageNames.CSharp), false }
};

AssertFormatAfterTypeChar(code, expected, optionSet);
Expand Down Expand Up @@ -1357,7 +1356,7 @@ class C

var optionSet = new Dictionary<OptionKey2, object>
{
{ new OptionKey2(FeatureOnOffOptions.AutoFormattingOnTyping, LanguageNames.CSharp), false }
{ new OptionKey2(FormattingOptions2.AutoFormattingOnTyping, LanguageNames.CSharp), false }
};

AssertFormatAfterTypeChar(code, expected, optionSet);
Expand Down
Loading

0 comments on commit 6967597

Please sign in to comment.