Skip to content

Fix nested-lambda variable collision#70

Merged
koenbeuk merged 1 commit into
mainfrom
fix/variable-collission
Jun 2, 2026
Merged

Fix nested-lambda variable collision#70
koenbeuk merged 1 commit into
mainfrom
fix/variable-collission

Conversation

@koenbeuk
Copy link
Copy Markdown
Collaborator

@koenbeuk koenbeuk commented Jun 2, 2026

Resolve variable name collisions in nested lambdas by incorporating a unique prefix for each lambda's parameters. This change prevents compile errors related to duplicate variable declarations in generated interceptors. Additional tests ensure that the generated code compiles correctly under these conditions.

Copilot AI review requested due to automatic review settings June 2, 2026 15:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a codegen correctness issue in ExpressionTreeEmitter where nested lambda parameter locals could collide across sibling lambdas emitted into the same interceptor body, causing CS0128 duplicate-variable compile errors. The change aligns nested-lambda parameter variable naming with the existing per-lambda _varPrefix scheme used elsewhere in the interceptor generator.

Changes:

  • Prefix nested-lambda ParameterExpression local variable names with the per-lambda _varPrefix to ensure uniqueness across sibling lambda emissions.
  • Add a regression test that compiles the generated interceptor for a Join with sibling key selectors that each contain a nested lambda with the same parameter name.
  • Update verified snapshot outputs to reflect the new prefixed parameter variable names.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/ExpressiveSharp.Generator.Tests/PolyfillInterceptorGenerator/JoinTests.cs Adds a regression compilation test covering sibling key-selector lambdas with nested-lambda parameter name collisions.
tests/ExpressiveSharp.Generator.Tests/PolyfillInterceptorGenerator/ExecuteUpdateTests.ExecuteUpdateAsync_GeneratesInterceptor.verified.txt Updates snapshot to reflect prefixed nested-lambda parameter variable names.
tests/ExpressiveSharp.Generator.Tests/PolyfillInterceptorGenerator/ExecuteUpdateTests.ExecuteUpdate_SetProperty_WithSwitchExpression.verified.txt Updates snapshot to reflect prefixed nested-lambda parameter variable names.
tests/ExpressiveSharp.Generator.Tests/PolyfillInterceptorGenerator/ExecuteUpdateTests.ExecuteUpdate_SetProperty_WithNullConditional.verified.txt Updates snapshot to reflect prefixed nested-lambda parameter variable names.
tests/ExpressiveSharp.Generator.Tests/PolyfillInterceptorGenerator/ExecuteUpdateTests.ExecuteUpdate_SetProperty_ConstantValue.verified.txt Updates snapshot to reflect prefixed nested-lambda parameter variable names.
src/ExpressiveSharp.Generator/Emitter/ExpressionTreeEmitter.cs Ensures nested lambda parameter locals include _varPrefix, preventing cross-emitter collisions in shared interceptor bodies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@koenbeuk koenbeuk merged commit d7d0f79 into main Jun 2, 2026
18 checks passed
@koenbeuk koenbeuk deleted the fix/variable-collission branch June 2, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants