Skip to content

Commit 656dd5f

Browse files
Fixup
1 parent a45616a commit 656dd5f

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/Analyzers/CSharp/Tests/UseAutoProperty/UseAutoPropertyTests.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3233,7 +3233,7 @@ public Test()
32333233
"""
32343234
public sealed class Test
32353235
{
3236-
public static Test Instance { get; private set; }
3236+
public static Test Instance { get => field!; private set; }
32373237
32383238
public Test()
32393239
{
@@ -3260,7 +3260,7 @@ static Test()
32603260
"""
32613261
public sealed class Test
32623262
{
3263-
public static Test Instance { get; } = new Test();
3263+
public static Test Instance => field!;
32643264
}
32653265
""");
32663266

@@ -3286,7 +3286,11 @@ public Test()
32863286
"""
32873287
public sealed class Test
32883288
{
3289-
public static Test Instance { get; set; }
3289+
public static Test Instance
3290+
{
3291+
get => field!;
3292+
set;
3293+
}
32903294
32913295
public Test()
32923296
{

src/Analyzers/Core/CodeFixes/UseAutoProperty/AbstractUseAutoPropertyCodeFixProvider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,12 @@ private async Task<SyntaxNode> FormatAsync(
484484
CancellationToken cancellationToken)
485485
{
486486
var isWrittenOutsideConstructor = false;
487-
// Only include constructors that match the static-ness of the field.
488-
// For a static field, only static constructors are relevant.
489-
// For an instance field, only instance constructors are relevant.
487+
488+
// Only include constructors that match the static-ness of the field. For a static field, only static
489+
// constructors are relevant. For an instance field, only instance constructors are relevant.
490490
var constructorSpans = field.ContainingType
491491
.GetMembers()
492-
.Where(m => m.IsConstructor() && m.IsStatic == field.IsStatic)
492+
.Where(m => field.IsStatic ? m.IsStaticConstructor() : m.IsConstructor())
493493
.SelectMany(c => c.DeclaringSyntaxReferences)
494494
.Select(s => s.GetSyntax(cancellationToken))
495495
.Select(n => n.FirstAncestorOrSelf<TConstructorDeclaration>())

0 commit comments

Comments
 (0)