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

Adding ! fails to suppress warning #26618

Closed
jcouv opened this issue May 4, 2018 · 2 comments
Closed

Adding ! fails to suppress warning #26618

jcouv opened this issue May 4, 2018 · 2 comments
Assignees
Milestone

Comments

@jcouv
Copy link
Member

jcouv commented May 4, 2018

The sample below shows two problems:
1. T is actually constrained to a class type, so return null should be ok
2. Adding ! did not supress this warning

public class C {
    public T M<T>()  where T : C {
        return null!; // warning CS8625: Cannot convert null literal to non-nullable reference or unconstrained type parameter.
    }
}
@jcouv jcouv added this to the 16.0 milestone May 4, 2018
@jcouv jcouv changed the title Adding ! fails to suppress warning Adding ! fails to suppress warning, and shouldn't be need for async method anyways May 4, 2018
@jcouv jcouv changed the title Adding ! fails to suppress warning, and shouldn't be need for async method anyways Adding ! fails to suppress warning May 4, 2018
@cston
Copy link
Member

cston commented May 4, 2018

! should suppress the warning (that is a valid bug), but since T is constrained to a reference type, the method could be declared as returning T? to avoid the warning.

@jcouv
Copy link
Member Author

jcouv commented Aug 5, 2018

This seems to have been fixed already (sharplab).
Never mind. Still repros on my local branch.

@jcouv jcouv assigned jcouv and unassigned cston Aug 5, 2018
@jcouv jcouv added the 4 - In Review A fix for the issue is submitted for review. label Aug 5, 2018
@jcouv jcouv closed this as completed Aug 6, 2018
@jcouv jcouv removed the 4 - In Review A fix for the issue is submitted for review. label Aug 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants