-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Fix ref safety holes in delegate conversions across old/new rule boundaries #80876
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
Draft
Copilot
wants to merge
10
commits into
main
Choose a base branch
from
copilot/fix-ref-safety-holes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
- Detect when a method group conversion creates a synthesized delegate with mismatched escape rules - Report error when converting methods from old-rules assemblies to synthesized delegates in new-rules contexts - Update test to expect error at delegate conversion point Co-authored-by: jjonescz <[email protected]>
- Add test for out parameters - Add test verifying no error when both methods use new rules - Add test verifying no error when both methods use old rules - Add test verifying no error when no ref structs are involved Co-authored-by: jjonescz <[email protected]>
The fix now correctly reports an error when converting a method with UnscopedRef parameters from an old-rules assembly to a synthesized delegate in a new-rules context. Co-authored-by: jjonescz <[email protected]>
The fix now correctly reports errors for synthesized delegate conversions with UnscopedRef attribute mismatches across old/new rules boundaries. Co-authored-by: jjonescz <[email protected]>
Copilot
AI
changed the title
[WIP] Fix ref safety holes with synthesized delegates
Fix ref safety holes in synthesized delegate conversions across old/new rule boundaries
Oct 24, 2025
Copilot finished work on behalf of
jjonescz
October 24, 2025 13:08
jjonescz
reviewed
Oct 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Remove issue link comment as code is self-documenting - Remove superfluous blank line in test - Inline isSynthesizedDelegate variable - Share TryGetThisParameter logic to avoid duplication - Use ERR_MethDelegateMismatch instead of ERR_ScopedMismatchInParameterOfTarget for correct error message formatting - Update all test expectations to match new error message Co-authored-by: jjonescz <[email protected]>
…aging - Add ERR_RefSafetyInDelegateConversion (9340) with clear error message explaining the ref safety issue - Update code to use new error instead of generic ERR_MethDelegateMismatch - Add explanatory comment for RequiresValidScopedOverrideForRefSafety check - Update ErrorFacts.cs to handle new error code - Update all test expectations to use new error with better message Co-authored-by: jjonescz <[email protected]>
Copilot finished work on behalf of
jjonescz
October 27, 2025 11:43
jjonescz
reviewed
Oct 27, 2025
…egate behavior - Add detailed comment explaining why we check synthesized delegates specifically - Add test documenting that custom delegates currently don't produce errors/warnings - The comment clarifies that synthesized delegates are created implicitly in the calling context and users don't have explicit control over their definition, warranting an error instead of warning Co-authored-by: jjonescz <[email protected]>
- Remove check for SynthesizedDelegateInvokeMethod to apply fix to all delegates - Update RefSafetyRules_CustomDelegate test to expect error - This is a breaking change: cross-version delegate conversions that previously produced warnings will now produce errors when ref-safety violations exist - Additional test updates needed for existing tests that expect warnings Co-authored-by: jjonescz <[email protected]>
- Restore if statement that guards CheckValidScopedOverride call - This was accidentally removed in previous commit Co-authored-by: jjonescz <[email protected]>
Copilot
AI
changed the title
Fix ref safety holes in synthesized delegate conversions across old/new rule boundaries
Fix ref safety holes in delegate conversions across old/new rule boundaries
Oct 27, 2025
Copilot finished work on behalf of
jjonescz
October 27, 2025 15:48
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.
Fix ref safety holes in delegate conversions
This PR fixes a ref safety hole that occurred when converting methods from old-rules assemblies to delegates in new-rules contexts (issue #76087).
Summary of Changes
Core Fix (
Binder_Conversions.cs)Added validation in
CheckParameterModifierMismatchMethodConversionto detect when:When all conditions are met, a new error (
ERR_RefSafetyInDelegateConversion) is now reported at the delegate conversion point with a clear, user-friendly error message.Breaking Change: This check applies to ALL delegates (both synthesized and custom), not just synthesized delegates. Cross-version delegate conversions that previously produced warnings will now produce errors when ref-safety violations exist. This is necessary because the ref-safety hole exists for all delegate types when crossing old/new rule boundaries.
New Error Code
ERR_RefSafetyInDelegateConversion(9340) with message: "Cannot convert method group '{0}' to delegate type '{1}' due to mismatched ref safety requirements between the method and delegate."ErrorFacts.csto properly handle the new error code.Test Updates
RefSafetyRules_SynthesizedDelegatetest to expect error at delegate conversion for synthesized delegatesRefSafetyRules_CustomDelegatetest to expect error for custom delegatesTesting
Impact
This change prevents ref safety violations that could occur when using delegates as a boundary between old and new ref safety rules, making the compiler more robust and safer while providing clear, actionable error messages to users about what went wrong. This is a breaking change that upgrades certain cross-version warnings to errors to properly address the ref-safety hole.
Fixes #76087
Original prompt
Fixes #76087
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.