Skip to content

Record anonymous type dependencies during initial binding#81024

Merged
AlekseyTs merged 2 commits intodotnet:mainfrom
AlekseyTs:Issue73558
Nov 7, 2025
Merged

Record anonymous type dependencies during initial binding#81024
AlekseyTs merged 2 commits intodotnet:mainfrom
AlekseyTs:Issue73558

Conversation

@AlekseyTs
Copy link
Contributor

Fixes #73558

@AlekseyTs AlekseyTs requested a review from a team as a code owner November 4, 2025 16:57
@AlekseyTs AlekseyTs requested review from a team and removed request for a team November 4, 2025 18:35
@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler Please review

1 similar comment
@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler Please review

public bool ReportMissingOrErroneousSymbolsForDelegates(BindingDiagnosticBag diagnostics)
{
// If we start reporting errors for non-Special types or members here,
// we need to call this method from ConstructAnonymousDelegateSymbol to callect dependencies.
Copy link
Member

@jjonescz jjonescz Nov 5, 2025

Choose a reason for hiding this comment

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

Suggested change
// we need to call this method from ConstructAnonymousDelegateSymbol to callect dependencies.
// we need to call this method from ConstructAnonymousDelegateSymbol to collect dependencies.
``` #Resolved

{
if (diagnostics.AccumulatesDependencies)
{
var depencies = BindingDiagnosticBag.GetInstance(withDependencies: true, withDiagnostics: false);
Copy link
Member

@jjonescz jjonescz Nov 5, 2025

Choose a reason for hiding this comment

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

Suggested change
var depencies = BindingDiagnosticBag.GetInstance(withDependencies: true, withDiagnostics: false);
var dependencies = BindingDiagnosticBag.GetInstance(withDependencies: true, withDiagnostics: false);
``` #Resolved

/// Given anonymous type descriptor provided constructs an anonymous type symbol.
/// </summary>
public NamedTypeSymbol ConstructAnonymousTypeSymbol(AnonymousTypeDescriptor typeDescr)
public NamedTypeSymbol ConstructAnonymousTypeSymbol(AnonymousTypeDescriptor typeDescr, BindingDiagnosticBag diagnostics)
Copy link
Member

@jjonescz jjonescz Nov 5, 2025

Choose a reason for hiding this comment

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

Consider renaming diagnostics or adding a doc comment, so it's clearer at the callsites that it's only used to collect dependencies (and hence why it's fine to pass BindingDiagnosticBag.Discarded sometimes) #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider renaming diagnostics or adding a doc comment, so it's clearer at the callsites that it's only used to collect dependencies (and hence why it's fine to pass BindingDiagnosticBag.Discarded sometimes)

That is not the reason why it is fine to pass BindingDiagnosticBag.Discarded. In fact, that would be a wrong reason to do that. Also, it is fine to pass BindingDiagnosticBag.Discarded to pretty much any function that takes a BindingDiagnosticBag when there is no intent to use the information that might be collected, except those that are going to crash because they use DiagniosticBag directly (we have a small amount of functions like that). Why we might have no intent to use the information depends on each specific situation. However, in general, if we intend to preserve diagnostics, we usually should preserve dependencies as well. Also, there would be nothing wrong for this function to report a diagnostic if we decide that it is beneficials. Callers should make no assumption about what is being reported inside. At the moment, we don't report any diagnostics here, because all of it will be reported when we attempt to emit anyway. Reporting it here as well is going to produce a lot of duplicate errors.


Public Function ReportMissingOrErroneousSymbols(diagnostics As BindingDiagnosticBag, hasClass As Boolean, hasDelegate As Boolean, hasKeys As Boolean) As Boolean
' If we start reporting errors for non-Special types or members here when hasClass is false,
' we need to call this method from ConstructAnonymousDelegateSymbol to callect dependencies.
Copy link
Member

@jjonescz jjonescz Nov 5, 2025

Choose a reason for hiding this comment

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

Suggested change
' we need to call this method from ConstructAnonymousDelegateSymbol to callect dependencies.
' we need to call this method from ConstructAnonymousDelegateSymbol to collect dependencies.
``` #Resolved

@AlekseyTs AlekseyTs requested a review from a team November 5, 2025 14:20
@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler For a second review

1 similar comment
@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler For a second review

@AlekseyTs AlekseyTs enabled auto-merge (squash) November 7, 2025 17:38
@AlekseyTs AlekseyTs merged commit 48c74d9 into dotnet:main Nov 7, 2025
24 of 25 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Nov 7, 2025
@davidwengier davidwengier modified the milestones: Next, 18.3 Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assembly references used by anonymous types are not added to the set of used assembly references.

4 participants