Skip to content
Discussion options

You must be logged in to vote

I think the problem is code like the following:

#nullable enable

abstract class Base
{
    public virtual void M<T>(T? x) where T : struct {}
    public virtual void M<T>(T? x) where T : class {}
}

class Derived : Base
{
    public override void M<T>(T? x) {}
}

In Derived, T? is understood as Nullable<T>, so where T : struct is inferred. That also means adding the where T : class overload to the class after the where T : struct overload is not a source breaking change.

But if it was possible to infer where T : class, as you suggest, then adding the where T : struct overload would be a source breaking change.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by jnm2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants