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

makeNotNullMembersMaybeNull - skip primary constructor capture fields #68441

Merged
merged 1 commit into from
Jun 7, 2023
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 @@ -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 @@ -15389,6 +15389,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