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

Fix circularity issue with binding const local #75371

Merged
merged 5 commits into from
Oct 11, 2024
Merged

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Oct 3, 2024

Fixes #75353

Opened issue #75416 (wrong binder used in switch expression binding)
Opened issue #75437 (injected binders may get dropped by GetBinder)

@jcouv jcouv marked this pull request as ready for review October 7, 2024 19:56
@jcouv jcouv requested a review from a team as a code owner October 7, 2024 19:56
Copy link
Contributor

@RikkiGibson RikkiGibson left a comment

Choose a reason for hiding this comment

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

Just one minor question, otherwise looks good

Copy link
Member

@333fred 333fred Oct 7, 2024

Choose a reason for hiding this comment

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

Consider adding a test for a collection expression like [x]. #Resolved

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Oct 8, 2024

Consider opening an issue to check for other binders that are created on the fly, which could be "lost" in similar scenarios. #Closed

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Oct 8, 2024

Done with review pass (commit 1) #Closed

if (node.Initializer is { } initializer)
{
var oldEnclosing = _enclosing;
var localInProgressBinder = new LocalInProgressBinder(initializer, _enclosing);
Copy link
Contributor

@AlekseyTs AlekseyTs Oct 8, 2024

Choose a reason for hiding this comment

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

new LocalInProgressBinder(initializer, _enclosing)

Would it make sense to limit creation of the extra binder to const declarations? #Closed

@@ -536,7 +536,25 @@ public LocalWithInitializer(
Debug.Assert(initializer != null);

_initializer = initializer;
_initializerBinder = initializerBinder;
_initializerBinder = initializerBinder.GetBinder(initializer) ?? new LocalInProgressBinder(_initializer, initializerBinder);
Copy link
Contributor

@AlekseyTs AlekseyTs Oct 8, 2024

Choose a reason for hiding this comment

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

new LocalInProgressBinder

We probably don't want to inject this binder for non-constants. #Closed

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 3)

@@ -536,7 +536,26 @@ public LocalWithInitializer(
Debug.Assert(initializer != null);

_initializer = initializer;
_initializerBinder = initializerBinder;
_initializerBinder = initializerBinder.GetBinder(initializer);
Copy link
Contributor

@AlekseyTs AlekseyTs Oct 9, 2024

Choose a reason for hiding this comment

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

initializerBinder.GetBinder(initializer)

It is expected to get null from this call for non-constant declarations. Most likely this is the reason why CI is failing. #Closed

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 4)

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 5)

@jcouv jcouv merged commit d1afb2f into dotnet:main Oct 11, 2024
24 checks passed
@jcouv jcouv deleted the const-loop branch October 11, 2024 17:16
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Oct 11, 2024
@akhera99 akhera99 modified the milestones: Next, 17.13 P1 Oct 28, 2024
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.

crash on assigning result of a switch expression to a constant
5 participants