Skip to content

Unsafe evolution: handle remaining member kinds#82043

Merged
jjonescz merged 61 commits into
dotnet:features/UnsafeEvolutionfrom
jjonescz:Unsafe-10-MoreMemberKinds
Jan 26, 2026
Merged

Unsafe evolution: handle remaining member kinds#82043
jjonescz merged 61 commits into
dotnet:features/UnsafeEvolutionfrom
jjonescz:Unsafe-10-MoreMemberKinds

Conversation

@jjonescz

@jjonescz jjonescz commented Jan 16, 2026

Copy link
Copy Markdown
Member

Test plan: #81207
OHI not handled as part of this PR.
Delegates handled according to this open question: https://github.com/dotnet/csharplang/blob/79da45137622071d3c80ebe0a1296387af67afb9/proposals/unsafe-evolution.md#delegate-type-unsafety (i.e., it's not possible to mark delegates as caller-unsafe - I'd expect this to be approved and even if not, it seems like a good starting point - see also comments by jkotas under dotnet/csharplang#9831).

If you want to see what location is covered by which test, the individual commits should show that (although they are not super clean, i.e., there are some fixups later, etc.).

@jjonescz jjonescz requested a review from jcouv January 22, 2026 19:25
Comment thread src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
Comment thread src/Compilers/CSharp/Portable/Binder/LockBinder.cs
Comment thread src/Compilers/CSharp/Portable/Binder/UsingStatementBinder.cs
Comment thread src/Compilers/CSharp/Portable/Binder/UsingStatementBinder.cs
public readonly void ReportDiagnosticsIfUnsafeMemberAccess(Binder binder, SyntaxNodeOrToken node, SyntaxNode syntax, BindingDiagnosticBag diagnostics)
{
var getEnumeratorMethod = this.GetEnumeratorInfo?.Method;
if (getEnumeratorMethod != null) binder.ReportDiagnosticsIfUnsafeMemberAccess(diagnostics, getEnumeratorMethod, node);

@jcouv jcouv Jan 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

getEnumeratorMethod != null

For symbols, I believe this comparison will actually call the user-defined equality operator. Is that intentional? If not consider is null.
Also applies below #Closed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm actually surprised this compiled, I thought we obsoleted these.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm actually surprised this compiled, I thought we obsoleted these.

Only the operator on TypeSymbol is obsolete (because it can't take TypeCompareKind parameter I think).

For symbols, I believe this comparison will actually call the user-defined equality operator. Is that intentional?

I think it's functionally equivalent, but can use is null to make it clearer.

Comment thread src/Compilers/CSharp/Portable/Binder/Binder_Await.cs
@jcouv

jcouv commented Jan 22, 2026

Copy link
Copy Markdown
Member
            i.M2();

nit: consider including the happy case with unsafe block. May also apply to other added tests #Closed


Refers to: src/Compilers/CSharp/Test/CSharp15/UnsafeEvolutionTests.cs:3089 in 6e68678. [](commit_id = 6e68678, deletion_comment = False)

@jcouv jcouv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Done with review pass (commit 57)

@333fred 333fred left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Done review pass. Did not review tests yet.

Comment thread src/Compilers/CSharp/Portable/Binder/Binder_Attributes.cs
}

static void reportObsoleteDiagnostics(Binder @this, BindingDiagnosticBag diagnostics, MethodSymbol method, SyntaxNode syntax)
static void reportUseSiteDiagnostics(Binder @this, BindingDiagnosticBag diagnostics, MethodSymbol method, SyntaxNode syntax)

@333fred 333fred Jan 23, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These aren't use site diagnostics (or at least, I don't see any determination of the use site diagnostics of the symbol involved). This should probably be named reportObsoleteAndUnsafeDiagnostics. #Closed

Comment thread src/Compilers/CSharp/Portable/Binder/Binder_Await.cs
if (symbol.Kind is not (SymbolKind.Event or SymbolKind.Property))
{
ReportDiagnosticsIfObsolete(diagnostics, symbol, node, hasBaseReceiver: false);
AssertNotUnsafeMemberAccess(symbol);

@333fred 333fred Jan 23, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Prototype, since we may need unsafe fields? #Closed

Comment thread src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
Comment thread src/Compilers/CSharp/Portable/Binder/Binder_Symbols.cs
Comment thread src/Compilers/CSharp/Portable/Binder/Binder_Symbols.cs
public readonly void ReportDiagnosticsIfUnsafeMemberAccess(Binder binder, SyntaxNodeOrToken node, SyntaxNode syntax, BindingDiagnosticBag diagnostics)
{
var getEnumeratorMethod = this.GetEnumeratorInfo?.Method;
if (getEnumeratorMethod != null) binder.ReportDiagnosticsIfUnsafeMemberAccess(diagnostics, getEnumeratorMethod, node);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm actually surprised this compiled, I thought we obsoleted these.

/// </summary>
internal abstract bool IsRequired { get; }

internal sealed override CallerUnsafeMode CallerUnsafeMode => CallerUnsafeMode.None;

@333fred 333fred Jan 23, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe leave a PROTOTYPE? #Resolved

@jcouv jcouv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM Thanks (commit 61). I'll add a follow-up note to test plan regarding well-known members in general

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