Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for BackingField instead of IsAutoProperty in NullableWalker #75872

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ static IEnumerable<Symbol> getAllMembersToBeDefaulted(Symbol requiredMember)
}

static Symbol getFieldSymbolToBeInitialized(Symbol requiredMember)
=> requiredMember is SourcePropertySymbol { IsAutoProperty: true } prop ? prop.BackingField : requiredMember;
=> requiredMember is SourcePropertySymbolBase { BackingField: { } backingField } ? backingField : requiredMember;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4517,17 +4517,19 @@ public C(bool unused) : this()
);
}

[Fact, CompilerTrait(CompilerFeature.NullableReferenceTypes)]
[Theory, CompilerTrait(CompilerFeature.NullableReferenceTypes)]
[WorkItem(6754, "https://github.com/dotnet/csharplang/issues/6754")]
public void RequiredMemberSuppressesNullabilityWarnings_MemberNotNull_ChainedConstructor_03()
[InlineData("public string Property2 { get; set; }")]
[InlineData("public string Property2 { get => field; set => field = value; }")]
public void RequiredMemberSuppressesNullabilityWarnings_MemberNotNull_ChainedConstructor_03(string property2Definition)
{
var code = """
var code = $$"""
using System.Diagnostics.CodeAnalysis;
#nullable enable
class C
{
public required string Property1 { get => Property2; [MemberNotNull(nameof(Property2))] set => Property2 = value; }
public string Property2 { get; set; }
{{property2Definition}}

public C() { }
public C(bool unused) : this()
Expand All @@ -4549,17 +4551,19 @@ public C(bool unused) : this()
);
}

[Fact, CompilerTrait(CompilerFeature.NullableReferenceTypes)]
[Theory, CompilerTrait(CompilerFeature.NullableReferenceTypes)]
[WorkItem(6754, "https://github.com/dotnet/csharplang/issues/6754")]
public void RequiredMemberSuppressesNullabilityWarnings_MemberNotNull_ChainedConstructor_04()
[InlineData("public string Property2 { get; set; }")]
[InlineData("public string Property2 { get => field; set => field = value; }")]
public void RequiredMemberSuppressesNullabilityWarnings_MemberNotNull_ChainedConstructor_04(string property2Definition)
{
var code = """
var code = $$"""
using System.Diagnostics.CodeAnalysis;
#nullable enable
class C
{
public required string Property1 { get => Property2; [MemberNotNull(nameof(Property2))] set => Property2 = value; }
public string Property2 { get; set; }
{{property2Definition}}

public C() { }
[SetsRequiredMembers]
Expand Down
Loading