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

Nullability mismatch reported for generic return type of implementation of unannotated method #29675

Closed
cston opened this issue Sep 4, 2018 · 5 comments

Comments

@cston
Copy link
Member

cston commented Sep 4, 2018

A warning is reported for IEnumerable<T>.GetEnumerator():

using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
[module: NonNullTypes]
class Enumerable<T> : IEnumerable<T>
{
    IEnumerator<T> IEnumerable<T>.GetEnumerator() => throw null; // warning
    IEnumerator IEnumerable.GetEnumerator() => throw null;
}
(7,35): warning CS8616: Nullability of reference types in return type doesn't match
    implemented member 'IEnumerator<T> IEnumerable<T>.GetEnumerator()'.
@cston cston added this to the 16.0 milestone Sep 4, 2018
@jaredpar jaredpar added the Bug label Sep 5, 2018
@cston
Copy link
Member Author

cston commented Nov 13, 2018

Fixed in #30913?

@cston cston closed this as completed Nov 13, 2018
@DavidArno
Copy link

Did #30913 make it into VS2019 preview 1? If it did, this problem still persists as I'm getting the same warning testing C# 8 beta there.

@alrz
Copy link
Member

alrz commented Dec 6, 2018

@DavidArno The merged PR is targeting preview 2 branch.

@DavidArno
Copy link

@alrz, thanks. I couldn't work that out for myself, so glad you were on hand to work it out for me! 😁

@jskeet
Copy link

jskeet commented Dec 17, 2018

One thing to note is that at least in my experience, this only occurs for explicit interface implementation. So this would be fine:

public IEnumerator<T> GetEnumerator() => throw null;

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

5 participants