Add LocalRewritingValidator check for BoundUnconvertedObjectCreationExpression#80724
Merged
Add LocalRewritingValidator check for BoundUnconvertedObjectCreationExpression#80724
Conversation
…xpression Co-authored-by: jcouv <12466233+jcouv@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Modify LocalRewritingValidator to restrict BoundUnconvertedObjectCreation
Add LocalRewritingValidator check for BoundUnconvertedObjectCreationExpression
Oct 14, 2025
333fred
approved these changes
Oct 14, 2025
RikkiGibson
approved these changes
Oct 15, 2025
This was referenced Oct 17, 2025
This was referenced Oct 23, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #57179
This PR adds a validation check in
LocalRewritingValidatorto enforce thatBoundUnconvertedObjectCreationExpressionnodes do not survive past local rewriting.Background
BoundUnconvertedObjectCreationExpressionrepresents target-typednew()expressions before they are converted to their actual target type during binding. These nodes should be fully converted during the binding phase and should never reach the local rewriting phase.The main
LocalRewriterclass already has aVisitUnconvertedObjectCreationExpressionmethod that throwsExceptionUtilities.Unreachable(), indicating these nodes are unexpected during local rewriting. However, there was no corresponding DEBUG-time validation to catch cases where such nodes might inadvertently survive into the local rewriting phase.Changes
Added a
VisitUnconvertedObjectCreationExpressionmethod to theLocalRewritingValidatorclass that:Fail(node)to trigger a debug assertion if an unconverted object creation expression is encounteredVisitDefaultLiteral,VisitUsingStatement, etc.LocalRewritingValidatorclass is#if DEBUG)This provides an additional safety net to catch potential bugs during development where unconverted object creation expressions might leak into the local rewriting phase.
Testing
new()expressions)The change is minimal (6 lines) and follows established patterns in the codebase.
Originally requested by @jcouv in #57091 (comment)
Co-authored-by: jcouv 12466233+jcouv@users.noreply.github.com
Original prompt
Fixes #57179
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.