Skip to content

Print shifts and repeated block expressions correctly in ExpressionPrinter - #39320

Merged
AndriySvyryd merged 1 commit into
dotnet:mainfrom
ilkertskn:fix/expression-printer-block-and-shift
Oct 21, 2026
Merged

AndriySvyryd merged 1 commit into
dotnet:mainfrom
ilkertskn:fix/expression-printer-block-and-shift

Conversation

@ilkertskn

Copy link
Copy Markdown
Contributor

ExpressionPrinter had LeftShift/RightShift in its operator map but not in the Visit switch, so they fell back to Expression.ToString(). VisitBlock also used Except() to drop the result expression, which has set semantics: a block that reuses the same expression instance more than once, or whose result instance also appears earlier in the block, lost statements in the printed output.

  • [ x] I've read the guidelines for contributing and seen the walkthrough
  • [x ] I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • [x ] The code builds and tests pass locally (also verified by our automated build checks)
  • [x ] Commit messages follow this format:
        Summary of the changes
        - Detail 1
        - Detail 2

        Fixes #bugnumber
  • [x ] Tests for the changes have been added (for bug fixes / features)
  • [x ] Code follows the same patterns and style as existing code in this repo

…inter

ExpressionPrinter had LeftShift/RightShift in its operator map but not in the
Visit switch, so they fell back to Expression.ToString(). VisitBlock also used
Except() to drop the result expression, which has set semantics: a block that
reuses the same expression instance more than once, or whose result instance
also appears earlier in the block, lost statements in the printed output.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused implementation changes include regression coverage and have no unresolved review issues.

No open issues 🎉

What changed in this PR

This pull request fixes ExpressionPrinter output for shift operators and block expressions containing repeated expression instances.

Changes:

  • Routes LeftShift and RightShift through binary-expression printing.
  • Replaces set-based block filtering with positional filtering.
  • Adds regression tests for both scenarios.
File Description
test/​EFCore.Tests/​Query/​ExpressionPrinterTest.cs Adds regression coverage for shift operators and repeated block expressions.
src/​EFCore/​Query/​ExpressionPrinter.cs Corrects shift dispatch and preserves repeated block expressions by position.

Review effort: Lite

@AndriySvyryd
AndriySvyryd merged commit 875469f into dotnet:main Oct 21, 2026
20 checks passed
@AndriySvyryd

Copy link
Copy Markdown
Member

Thanks for your contribution!

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.

3 participants