Skip to content

Commit

Permalink
makeNotNullMembersMaybeNull - skip primary constructor capture fiel…
Browse files Browse the repository at this point in the history
…ds (#68441)

Fixes #68384.
  • Loading branch information
AlekseyTs authored Jun 7, 2023
1 parent 61853f2 commit 724a31f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,9 @@ void makeNotNullMembersMaybeNull()
case PropertySymbol:
// skip any manually implemented non-required properties.
continue;
case FieldSymbol { OriginalDefinition: SynthesizedPrimaryConstructorParameterBackingFieldSymbol }:
// Skip primary constructor capture fields, compiler initializes them with parameters' values
continue;
case FieldSymbol { IsConst: true }:
continue;
case FieldSymbol { AssociatedSymbol: PropertySymbol prop }:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15525,6 +15525,73 @@ .property instance int32 P2()
".Replace("[mscorlib]", ExecutionConditionUtil.IsDesktop ? "[mscorlib]" : "[netstandard]"));
}

[Fact]
[WorkItem("https://github.com/dotnet/roslyn/issues/68384")]
public void ParameterCapturing_152_NullableAnalysis()
{
var source = @"
#nullable enable

class B(string s)
{
public string S { get; } = s;
}

class C(B b)
: B(b.S)
{
string T() => b.S;
}";
var comp = CreateCompilation(source, options: TestOptions.ReleaseDll);
comp.VerifyDiagnostics();
}

[Fact]
[WorkItem("https://github.com/dotnet/roslyn/issues/68384")]
public void ParameterCapturing_153_NullableAnalysis()
{
var source = @"
#nullable enable

class B(System.Func<string> s)
{
public string S { get; } = s();
}

class C(B b)
: B(() => b.S)
{
string T() => b.S;
}";
var comp = CreateCompilation(source, options: TestOptions.ReleaseDll);
comp.VerifyDiagnostics();
}

[Fact]
[WorkItem("https://github.com/dotnet/roslyn/issues/68384")]
public void ParameterCapturing_154_NullableAnalysis()
{
var source = @"
#nullable enable

class B(System.Func<string> s)
{
public string S { get; } = s();
}

class C(B b)
: B(() =>
{
string local() => b.S;
return local();
})
{
string T() => b.S;
}";
var comp = CreateCompilation(source, options: TestOptions.ReleaseDll);
comp.VerifyDiagnostics();
}

[Fact]
public void CycleDueToIndexerNameAttribute_01()
{
Expand Down

0 comments on commit 724a31f

Please sign in to comment.