Skip to content
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

"Implement abstract class" should add the right generic constraint when a parameter is covariant in T? and constrained to be a subtype #71225

Closed
SolalPirelli opened this issue Dec 12, 2023 · 0 comments · Fixed by #76223
Assignees
Labels
Milestone

Comments

@SolalPirelli
Copy link

Similar to #62092 but even more specific. To be honest I don't even understand why the actual and expected behaviors here fail and succeed to compile respectively.

Version Used:

  • Microsoft Visual Studio Community 2022 Version 17.8.3 VisualStudio.17.Release/17.8.3+34330.188
  • C# Tools 4.8.0-7.23572.1+7b75981cf3bd520b86ec4ed00ec156c8bc48e4eb

Steps to Reproduce:

Given the following code, in a project with nullable enabled:

interface I<out T> { }

class C { }

abstract class Problem
{
    protected abstract void M<T>(I<T?> i) where T : C;
}

class Bad : Problem
{
}

Apply "Implement abstract class" on Bad.

Expected Behavior:
The following code compiles, so I think that's what should be generated:

    protected override void M<T>(I<T?> i) where T : class
    {
        throw new System.NotImplementedException();
    }

Actual Behavior:
The following is generated, which does not compile due to the generic constraint:

    protected override void M<T>(I<T?> i) where T : default
    {
        throw new System.NotImplementedException();
    }
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Dec 12, 2023
@Cosifne Cosifne removed the untriaged Issues and PRs which have not yet been triaged by a lead label Jul 3, 2024
@arunchndr arunchndr added this to the Backlog milestone Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment