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

Code before:
        [Fact]
        public void TestGeneric()
        {
            TestConditional(@"GetUserNonGeneric()? 1 : 2", null, Diagnostic(ErrorCode.ERR_NoImplicitConv, "GetUserNonGeneric()").WithArguments("C", "bool"));
            TestConditional(@"GetUserGeneric<T>()? 1 : 2", null, Diagnostic(ErrorCode.ERR_NoImplicitConv, "GetUserGeneric<T>()").WithArguments("D<T>", "bool"));
            TestConditional(@"GetTypeParameter<T>()? 1 : 2", null, Diagnostic(ErrorCode.ERR_NoImplicitConv, "GetTypeParameter<T>()").WithArguments("T", "bool"));
            TestConditional(@"GetVariantInterface<T, U>()? 1 : 2", null, Diagnostic(ErrorCode.ERR_NoImplicitConv, "GetVariantInterface<T, U>()").WithArguments("I<T, U>", "bool"));
        }

        [Fact]
        public void TestInvalidCondition()
        {
            // CONSIDER: dev10 reports ERR_ConstOutOfRange
            TestConditional("1 ? 2 : 3", null,
                Diagnostic(ErrorCode.ERR_NoImplicitConv, "1").WithArguments("int", "bool"));

            TestConditional("goo ? 'a' : 'b'", null,
                Diagnostic(ErrorCode.ERR_NameNotInContext, "goo").WithArguments("goo"));

            TestConditional("new Goo() ? GetObject() : null", null,
                Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Goo").WithArguments("Goo"));

            // CONSIDER: dev10 reports ERR_ConstOutOfRange
            TestConditional("1 ? null : null", null, parseOptions: TestOptions.Regular8,
                Diagnostic(ErrorCode.ERR_NoImplicitConv, "1").WithArguments("int", "bool"),
                Diagnostic(ErrorCode.ERR_InvalidQM, "1 ? null : null").WithArguments("<null>", "<null>"));
            TestConditional("1 ? null : null", null, parseOptions: TestOptions.Regular.WithLanguageVersion(MessageID.IDS_FeatureTargetTypedConditional.RequiredVersion()),
                Diagnostic(ErrorCode.ERR_NoImplicitConv, "1").WithArguments("int", "bool"),
                Diagnostic(ErrorCode.ERR_InvalidQM, "1 ? null : null").WithArguments("<null>", "<null>"));
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/67975")]
        public void SumTypeInTuple()
        {
            var source = """
                #nullable enable
                class C1 { }
                class C2 { }
                class C3 { }
                struct SumType<T1, T2> where T1 : notnull where T2 : notnull
                {
                    public static implicit operator SumType<T1, T2>(T1 _) => throw null!;
                    public static implicit operator SumType<T1, T2>(T2 _) => throw null!;
                }
                class D
                {
                    public (C1, SumType<C2, C3>) F;

                    public void M(C1 one, C2? two, C3? three)
                    {
                        if (three == null) return;

Review comment (suggestion):
>Diagnostic(ErrorCode.ERR_InvalidQM, "1 ? null : null").WithArguments("<null>", "<null>")); [](http://example.com/codeflow?start=16&length=90)

Similar suggestion #Closed

Code after:
            TestConditional(@"GetUserGeneric<T>()? 1 : 2", null, Diagnostic(ErrorCode.ERR_NoImplicitConv, "GetUserGeneric<T>()").WithArguments("D<T>", "bool"));
            TestConditional(@"GetTypeParameter<T>()? 1 : 2", null, Diagnostic(ErrorCode.ERR_NoImplicitConv, "GetTypeParameter<T>()").WithArguments("T", "bool"));
            TestConditional(@"GetVariantInterface<T, U>()? 1 : 2", null, Diagnostic(ErrorCode.ERR_NoImplicitConv, "GetVariantInterface<T, U>()").WithArguments("I<T, U>", "bool"));
        }

        [Fact]
        public void TestInvalidCondition()
        {
            // CONSIDER: dev10 reports ERR_ConstOutOfRange
            TestConditional("1 ? 2 : 3", null,
                Diagnostic(ErrorCode.ERR_NoImplicitConv, "1").WithArguments("int", "bool"));

            TestConditional("goo ? 'a' : 'b'", null,
                Diagnostic(ErrorCode.ERR_NameNotInContext, "goo").WithArguments("goo"));

            TestConditional("new Goo() ? GetObject() : null", null,
                Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Goo").WithArguments("Goo"));

            // CONSIDER: dev10 reports ERR_ConstOutOfRange
            TestConditional("1 ? null : null", null, parseOptions: TestOptions.Regular8,
                Diagnostic(ErrorCode.ERR_NoImplicitConv, "1").WithArguments("int", "bool")
                );
            TestConditional("1 ? null : null", null, parseOptions: TestOptions.Regular.WithLanguageVersion(MessageID.IDS_FeatureTargetTypedConditional.RequiredVersion()),
                Diagnostic(ErrorCode.ERR_NoImplicitConv, "1").WithArguments("int", "bool")
                );
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/67975")]
        public void SumTypeInTuple()
        {
            var source = """
                #nullable enable
                class C1 { }
                class C2 { }
                class C3 { }
                struct SumType<T1, T2> where T1 : notnull where T2 : notnull
                {
                    public static implicit operator SumType<T1, T2>(T1 _) => throw null!;
                    public static implicit operator SumType<T1, T2>(T2 _) => throw null!;
                }
                class D
                {
                    public (C1, SumType<C2, C3>) F;

                    public void M(C1 one, C2? two, C3? three)
                    {
                        if (three == null) return;
                        F = (one, two is not null ? two : three);
                    }
                }
                """;