Skip to content

Do not bail generating base type initializer in the presence of use site warnings#76347

Merged
333fred merged 3 commits intodotnet:mainfrom
333fred:required-cloning
Dec 11, 2024
Merged

Do not bail generating base type initializer in the presence of use site warnings#76347
333fred merged 3 commits intodotnet:mainfrom
333fred:required-cloning

Conversation

@333fred
Copy link
Member

@333fred 333fred commented Dec 10, 2024

We were returning early from generating a call to the base record copy constructor initializer if use site diagnostics reported any kind of diagnostic, including warnings. This isn't good in general, but is particularly bad for warnings like CS1701, which are typically suppressed by the SDK and results in what seems like a completely clean csc invocation skipping calling the base constructor. Fixes #72357.

@333fred 333fred requested a review from a team as a code owner December 10, 2024 00:55
@ghost ghost added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Dec 10, 2024
…ite warnings

We were returning early from generating a call to the base record copy constructor initializer if use site diagnostics reported any kind of diagnostic, including warnings. This isn't good in general, but is particularly bad for warnings like CS1701, which are typically suppressed by the SDK and results in what seems like a completely clean csc invocation skipping calling the base constructor. Fixes dotnet#72357.
@333fred
Copy link
Member Author

333fred commented Dec 10, 2024

@dotnet/roslyn-compiler for reviews

}

internal static bool ReportConstructorUseSiteDiagnostics(Location errorLocation, BindingDiagnosticBag diagnostics, bool suppressUnsupportedRequiredMembersError, in CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
internal static void ReportConstructorUseSiteDiagnostics(Location errorLocation, BindingDiagnosticBag diagnostics, bool suppressUnsupportedRequiredMembersError, in CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are lots of uses of this method, but this was the only one that did something conditional. That seemed like a bad thing to keep around, so I just made the method return void instead to prevent something like this from happening again.

@jcouv jcouv self-assigned this Dec 10, 2024
Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks (iteration 1)

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 2)

public record DerivedRecord : BaseRecord;
""", assemblyName: "Derived", references: [comp1.EmitToImageReference()], targetFramework: TargetFramework.Net80);

var verifier = CompileAndVerify(comp2, expectedOutput: ExecutionConditionUtil.IsCoreClr ? "False" : null, verify: Verification.FailsPEVerify);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsCoreClr

I think we usually use IsMonoOrCoreClr in situations like this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is specifically .NET 8, I don't think all mono environments would work, so I only did CoreClr.

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (commit 3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cloning a .NET 8 record deriving from a .NET 7 record leads to loss of members

4 participants