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

No warning when overriding method with out T? rather than out T #49131

Closed
cston opened this issue Nov 2, 2020 · 4 comments · Fixed by #49723
Closed

No warning when overriding method with out T? rather than out T #49131

cston opened this issue Nov 2, 2020 · 4 comments · Fixed by #49723
Assignees
Milestone

Comments

@cston
Copy link
Member

cston commented Nov 2, 2020

No warnings when compiling:

#nullable enable

abstract class A
{
    public abstract void F<T>(out T t);
}

class B : A
{
    public override void F<T>(out T? t) where T : default { t = default; }
}

Expected: A warning for B.F<T>():

(10,26): warning CS8765: Nullability of type of parameter 't' doesn't match overridden member
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 2, 2020
@cston cston self-assigned this Nov 2, 2020
@RikkiGibson
Copy link
Contributor

The root cause could be similar to #49071

@alrz
Copy link
Member

alrz commented Nov 2, 2020

out T? and out T wont warn for partial either, so it's probably the exact same issue.

@alrz
Copy link
Member

alrz commented Nov 2, 2020

We permit covariant nullables for output types, out and partial return type would be an exception..

@RikkiGibson
Copy link
Contributor

These signatures appears to be contravariant (override signature accepts a less specific type, which is only safe for inputs).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment