Repository: dotnet/roslyn
File: src/Compilers/CSharp/Test/Emit3/Semantics/CollectionExpressionTests_WithElement_Extra.cs (C#)

Code before:
        [CombinatorialValues("IDictionary", "IReadOnlyDictionary")] string typeName)
    {
        string source = $$"""
#nullable enable
                using System.Collections.Generic;
                class Program
                {
                    static {{typeName}}<K, V> Create1<K, V>(bool b, IEqualityComparer<K>? c1)
                    {
                        if (b) return new Dictionary<K, V>(c1);
                        return [with(c1)];
                    }
                    static {{typeName}}<K, V> Create2<K, V>(bool b, IEqualityComparer<K?> c2) where K : class
                    {
                        if (b) return new Dictionary<K, V>(c2);
                        return [with(c2)];
                    }
                    static {{typeName}}<K?, V> Create3<K, V>(bool b, IEqualityComparer<K> c3) where K : class
                    {
                        if (b) return new Dictionary<K?, V>(c3);
                        return [with(c3)];
                    }
                }
                """;
        var comp = CreateCompilation(source);
        // PROTO TYPE: Handle collection arguments in flow analysis: report CS8620 for 'with(c3)'.
        comp.VerifyEmitDiagnostics(
            // (17,45): warning CS8620: Argument of type 'IEqualityComparer<K>' cannot be used for parameter 'comparer' of type 'IEqualityComparer<K?>' in 'Dictionary<K?, V>.Dictionary(IEqualityComparer<K?> comparer)' due to differences in the nullability of reference types.
            //         if (b) return new Dictionary<K?, V>(c3);
            Diagnostic(ErrorCode.WRN_NullabilityMismatchInArgument, "c3").WithArguments("System.Collections.Generic.IEqualityComparer<K>", "System.Collections.Generic.IEqualityComparer<K?>", "comparer", "Dictionary<K?, V>.Dictionary(IEqualityComparer<K?> comparer)").WithLocation(17, 45));
    }

    [Theory]
    [CombinatorialData]
    public void InterfaceTarget_GenericMethod(
        [CombinatorialValues("IDictionary", "IReadOnlyDictionary")] string typeName)
    {
        string source = $$"""
                using System.Collections.Generic;
                class Program
                {
                    static {{typeName}}<K, V> Create<K, V>(IEqualityComparer<K> e)
                    {
                        return [with(e)];
                    }
                    static void Main()
                    {
                        Create<int, string>(null).Report();
                    }
                }
                """;

Review comment (suggestion):
```suggestion
        // https://github.com/dotnet/roslyn/issues/81860
        // Handle collection arguments in flow analysis: report CS8620 for 'with(c3)'.
```

Code after:
        [CombinatorialValues("IDictionary", "IReadOnlyDictionary")] string typeName)
    {
        string source = $$"""
#nullable enable
                using System.Collections.Generic;
                class Program
                {
                    static {{typeName}}<K, V> Create1<K, V>(bool b, IEqualityComparer<K>? c1)
                    {
                        if (b) return new Dictionary<K, V>(c1);
                        return [with(c1)];
                    }
                    static {{typeName}}<K, V> Create2<K, V>(bool b, IEqualityComparer<K?> c2) where K : class
                    {
                        if (b) return new Dictionary<K, V>(c2);
                        return [with(c2)];
                    }
                    static {{typeName}}<K?, V> Create3<K, V>(bool b, IEqualityComparer<K> c3) where K : class
                    {
                        if (b) return new Dictionary<K?, V>(c3);
                        return [with(c3)];
                    }
                }
                """;
        var comp = CreateCompilation(source);
        // https://github.com/dotnet/roslyn/issues/81860
        // Handle collection arguments in flow analysis: report CS8620 for 'with(c3)'.
        comp.VerifyEmitDiagnostics(
            // (17,45): warning CS8620: Argument of type 'IEqualityComparer<K>' cannot be used for parameter 'comparer' of type 'IEqualityComparer<K?>' in 'Dictionary<K?, V>.Dictionary(IEqualityComparer<K?> comparer)' due to differences in the nullability of reference types.
            //         if (b) return new Dictionary<K?, V>(c3);
            Diagnostic(ErrorCode.WRN_NullabilityMismatchInArgument, "c3").WithArguments("System.Collections.Generic.IEqualityComparer<K>", "System.Collections.Generic.IEqualityComparer<K?>", "comparer", "Dictionary<K?, V>.Dictionary(IEqualityComparer<K?> comparer)").WithLocation(17, 45));
    }

    [Theory]
    [CombinatorialData]
    public void InterfaceTarget_GenericMethod(
        [CombinatorialValues("IDictionary", "IReadOnlyDictionary")] string typeName)
    {
        string source = $$"""
                using System.Collections.Generic;
                class Program
                {
                    static {{typeName}}<K, V> Create<K, V>(IEqualityComparer<K> e)
                    {
                        return [with(e)];
                    }
                    static void Main()
                    {
                        Create<int, string>(null).Report();
                    }
                }