Skip to content

Explicitly specified type arguments should not be faded when they differ in nullability from inferred type arguments #45484

@jnm2

Description

@jnm2

Version Used: 16.6.2

No diagnostic should be shown here. The name cannot be simplified without adding at least two ! suppressions due to the choice of a generic type argument (string?) that would not make sense to choose here in the first place.

_ denotes a faded span.

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

#nullable enable

class C
{
    bool M(IEnumerable<string> s, [NotNullWhen(true)] out string? result)
    {
        // ℹ IDE0001 "Name can be simplified. Type argument specification is redundant."
        // 💡 Simplify name 'TryFirst<string>' 
        //               ________
        return s.TryFirst<string>(x => x.Length % 2 == 0, out result);
    }
}

static class Extensions
{
    public static bool TryFirst<T>(this IEnumerable<T> source, Func<T, bool> predicate, [MaybeNullWhen(false)] out T value)
    {
        throw new NotImplementedException();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Completed

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions