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 access to hoisted variables from reductions #104360

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

imb591
Copy link

@imb591 imb591 commented Jul 3, 2024

LambdaCompiler compiles several types of expressions by reducing them. Reductions may contain BlockExpressions not processed by VariableBinder, and in that case a scope is created for them on the fly during compilation. In particular, SwitchExpression and TypeBinaryExpression compilation can create a BlockExpression with a scope.

If such a BlockExpression is an immediate child of a LambdaExpression, it lost access to lambda parameters that were hoisted due to the propagation of the NeedsClosure flag for its scope from the lambda.

Always set the flag for such scopes to true, so that it always gets access to hoisted variables from the parent scope.

Fix #56262

LambdaCompiler compiles several types of expressions by reducing them.
Reductions may contain BlockExpressions not processed by VariableBinder,
and in that case a scope is created for them on the fly during
compilation. In particular, SwitchExpression and TypeBinaryExpression
compilation can create a BlockExpression with a scope.

If such a BlockExpression is an immediate child of a LambdaExpression,
it lost access to lambda parameters that were hoisted due to the
propagation of the NeedsClosure flag for its scope from the lambda.

Always set the flag for such scopes to true, so that its scope always
gets access to hoisted variables from the parent scope.

Fix dotnet#56262
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jul 3, 2024
Copy link
Contributor

Tagging subscribers to this area: @cston
See info in area-owners.md if you want to be subscribed.

@imb591
Copy link
Author

imb591 commented Jul 3, 2024

@dotnet-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Linq.Expressions community-contribution Indicates that the PR has been added by a community member
Projects
None yet
1 participant