Skip to content

Unsafe evolution: avoid unnecessary diagnostics on params collection declarations#83641

Open
jjonescz wants to merge 1 commit intodotnet:mainfrom
jjonescz:Unsafe-32-ParamsCollection
Open

Unsafe evolution: avoid unnecessary diagnostics on params collection declarations#83641
jjonescz wants to merge 1 commit intodotnet:mainfrom
jjonescz:Unsafe-32-ParamsCollection

Conversation

@jjonescz
Copy link
Copy Markdown
Member

@jjonescz jjonescz commented May 11, 2026

See #83452 (comment).
Test plan: #81207

Microsoft Reviewers: Open in CodeFlow

@jjonescz jjonescz requested review from 333fred and AlekseyTs May 11, 2026 09:44
@jjonescz jjonescz requested a review from a team as a code owner May 11, 2026 09:44
Copilot AI review requested due to automatic review settings May 11, 2026 09:44
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

This PR adjusts C# compiler collection-expression validation so that params collection parameter declarations don’t surface “unsafe member must be used in an unsafe context” diagnostics for the implicit constructor/add/builder members that would only be used by expanded call-site binding. Tests are updated accordingly to expect diagnostics only at relevant call sites / collection expressions.

Changes:

  • Thread an isParamsModifierValidation flag through collection-expression helper checks to suppress ReportDiagnosticsIfUnsafeMemberAccess during params-modifier validation.
  • Update SourceComplexParameterSymbol params-type validation to pass isParamsModifierValidation: true into the relevant helper checks.
  • Update Unsafe Evolution tests to remove now-unexpected diagnostics reported on params parameter declarations.

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
src/Compilers/CSharp/Test/CSharp15/UnsafeEvolutionTests.cs Removes expected diagnostics previously reported on params parameter declarations for unsafe collection builder/ctor/add members.
src/Compilers/CSharp/Portable/Symbols/Source/SourceComplexParameterSymbol.cs Passes isParamsModifierValidation: true when validating params collection types, avoiding unsafe-member diagnostics during declaration validation.
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolution.cs Updates call sites for HasCollectionExpressionApplicableConstructor/AddMethod with the new flag parameter.
src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/Conversions.cs Updates collection-expression conversion checks to pass isParamsModifierValidation: false.
src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs Updates the debug assertion call to HasCollectionExpressionApplicableAddMethod with isParamsModifierValidation: false.
src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs Adds isParamsModifierValidation plumbing and suppresses unsafe-member diagnostics in constructor/add/builder validation when validating a params modifier.

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.

2 participants