Skip to content

Incorrect warning about StringComparer differing in nullability from IEqualityComparer<string?> #28

Description

@jnm2

I'm not sure of the cause, but I'm seeing this on net472 using alpha 53 and Microsoft.NETCore.App.Ref 3.0.0:

void M(IEnumerable<string?> values)
{
    // CS8620 Argument of type 'StringComparer' cannot be used for parameter 'comparer' of type
    // 'IEqualityComparer<string?>' in 'IEnumerable<string?> Enumerable.Distinct<string?>(
    // IEnumerable<string?> source, IEqualityComparer<string?> comparer)' due to differences in
    // the nullability of reference types.
    //              ↓
    values.Distinct(StringComparer.CurrentCultureIgnoreCase);
}

StringComparer does in fact implement IEqualityComparer<string?>, not IEqualityComparer<string>. If I target netcoreapp3.0, the warning goes away.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions