Skip to content

Add LocalRewritingValidator check for BoundUnconvertedObjectCreationExpression#80724

Merged
jcouv merged 2 commits intomainfrom
copilot/modify-local-rewriting-validator
Oct 15, 2025
Merged

Add LocalRewritingValidator check for BoundUnconvertedObjectCreationExpression#80724
jcouv merged 2 commits intomainfrom
copilot/modify-local-rewriting-validator

Conversation

Copy link
Contributor

Copilot AI commented Oct 14, 2025

Fixes #57179

This PR adds a validation check in LocalRewritingValidator to enforce that BoundUnconvertedObjectCreationExpression nodes do not survive past local rewriting.

Background

BoundUnconvertedObjectCreationExpression represents target-typed new() 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 LocalRewriter class already has a VisitUnconvertedObjectCreationExpression method that throws ExceptionUtilities.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 VisitUnconvertedObjectCreationExpression method to the LocalRewritingValidator class that:

  • Calls Fail(node) to trigger a debug assertion if an unconverted object creation expression is encountered
  • Follows the same pattern as existing validator methods like VisitDefaultLiteral, VisitUsingStatement, etc.
  • Only executes in DEBUG builds (the entire LocalRewritingValidator class 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

  • All existing tests pass, including:
    • 163 ImplicitObjectCreationTests (target-typed new() expressions)
    • 94 TargetTyped tests
    • Full Compilers.slnf solution builds successfully

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

This section details on the original issue you should resolve

<issue_title>Can we modify LocalRewritingValidator to enforce that BoundUnconvertedObjectCreation does not survive past local rewriting?</issue_title>
<issue_description>Can we modify LocalRewritingValidator to enforce that BoundUnconvertedObjectCreation does not survive past local rewriting?

Originally posted by @jcouv in #57091 (comment)</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #57179


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

…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
Copilot AI requested a review from jcouv October 14, 2025 21:28
Copy link
Member

@jcouv jcouv 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 2)

@jcouv jcouv marked this pull request as ready for review October 14, 2025 22:09
@jcouv jcouv requested a review from a team as a code owner October 14, 2025 22:09
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.

Can we modify LocalRewritingValidator to enforce that BoundUnconvertedObjectCreation does not survive past local rewriting?

5 participants