Skip to content

Add support for variance safety for static interface members#1343

Closed
RexJaeschke wants to merge 1 commit intodotnet:draft-v9from
RexJaeschke:add-support-for-variance-safety-for-static-interface-members
Closed

Add support for variance safety for static interface members#1343
RexJaeschke wants to merge 1 commit intodotnet:draft-v9from
RexJaeschke:add-support-for-variance-safety-for-static-interface-members

Conversation

@RexJaeschke
Copy link
Contributor

I just discovered this V9 feature spec here. To make sure this was actually implemented in V9, I compiled the following code:

using System;
using System.Threading.Tasks;

public interface I<out T>
{
    static Task<T> F = Task.FromResult(default(T)); // No problem
    static Task<T> P => Task.FromResult(default(T));   //CS8904 in V8 but OK in V9
    static Task<T> M() => Task.FromResult(default(T));    //CS8904 in V8 but OK in V9
    static event EventHandler<T>? E; // CS8904 in V8 but OK in V9
}

The errors produced by V8 do not occur in V9.

@RexJaeschke RexJaeschke added this to the C# 9.0 milestone Jun 9, 2025
@RexJaeschke RexJaeschke added the type: feature This issue describes a new feature label Jun 9, 2025
@RexJaeschke RexJaeschke marked this pull request as draft June 9, 2025 19:56
@BillWagner
Copy link
Member

Closed in favor of #1471

@BillWagner BillWagner closed this Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature This issue describes a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants