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

Code before:
        {
            var source = """
                class C
                {
                    C M(bool b)
                    {
                        return b ? new(a) : default;
                    }
                }
                """;

            var comp = CreateCompilation(source);
            comp.VerifyDiagnostics(
                // (5,24): error CS0103: The name 'a' does not exist in the current context
                //         return b ? new(a) : default;
                Diagnostic(ErrorCode.ERR_NameNotInContext, "a").WithArguments("a").WithLocation(5, 24));

            var tree = comp.SyntaxTrees.First();
            var model = comp.GetSemanticModel(tree);

            var conditionalExpression = tree.GetCompilationUnitRoot().DescendantNodes().OfType<ConditionalExpressionSyntax>().Single();
            var typeInfo = model.GetTypeInfo(conditionalExpression);
            Assert.Null(typeInfo.Type);
            Assert.Equal("C", typeInfo.ConvertedType.ToTestDisplayString());

            var trueBranchTypeInfo = model.GetTypeInfo(conditionalExpression.WhenTrue);
            Assert.Equal("C", trueBranchTypeInfo.Type.ToTestDisplayString());
            Assert.Equal("C", trueBranchTypeInfo.ConvertedType.ToTestDisplayString());

            var falseBranchTypeInfo = model.GetTypeInfo(conditionalExpression.WhenFalse);
            Assert.Equal("C", falseBranchTypeInfo.Type.ToTestDisplayString());
            Assert.Equal("C", falseBranchTypeInfo.ConvertedType.ToTestDisplayString());
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81021")]
        public void ErrorRecovery_VariableDeclaration()
        {
            var source = """
                class C
                {
                    void M(bool b)
                    {
                        C c = b ? new(a) : default;
                    }
                }
                """;

            var comp = CreateCompilation(source);
            comp.VerifyDiagnostics(
                // (5,23): error CS0103: The name 'a' does not exist in the current context
                //         C c = b ? new(a) : default;

Review comment (suggestion):
>GetTypeInfo [](http://example.com/codeflow?start=43&length=11)

Let's also test behavior of GetSymbolInfo API #Closed

Code after:
        {
            var source = """
                class C
                {
                    C M(bool b)
                    {
                        return b ? new(a) : default;
                    }
                }
                """;

            var comp = CreateCompilation(source);
            comp.VerifyDiagnostics(
                // (5,24): error CS0103: The name 'a' does not exist in the current context
                //         return b ? new(a) : default;
                Diagnostic(ErrorCode.ERR_NameNotInContext, "a").WithArguments("a").WithLocation(5, 24));

            var tree = comp.SyntaxTrees.First();
            var model = comp.GetSemanticModel(tree);

            var conditionalExpression = tree.GetCompilationUnitRoot().DescendantNodes().OfType<ConditionalExpressionSyntax>().Single();
            var typeInfo = model.GetTypeInfo(conditionalExpression);
            Assert.Null(typeInfo.Type);
            Assert.Equal("C", typeInfo.ConvertedType.ToTestDisplayString());

            var trueBranch = conditionalExpression.WhenTrue;
            var trueBranchTypeInfo = model.GetTypeInfo(trueBranch);
            Assert.Equal("C", trueBranchTypeInfo.Type.ToTestDisplayString());
            Assert.Equal("C", trueBranchTypeInfo.ConvertedType.ToTestDisplayString());
            var trueBranchSymbolInfo = model.GetSymbolInfo(trueBranch);
            Assert.Null(trueBranchSymbolInfo.Symbol);
            Assert.Equal(CandidateReason.OverloadResolutionFailure, trueBranchSymbolInfo.CandidateReason);
            AssertEx.SetEqual(["C..ctor()"], trueBranchSymbolInfo.CandidateSymbols.ToTestDisplayStrings());
            var trueBranchSymbolGroup = model.GetMemberGroup(trueBranch);
            AssertEx.SetEqual(["C..ctor()"], trueBranchSymbolGroup.ToTestDisplayStrings());

            var falseBranchTypeInfo = model.GetTypeInfo(conditionalExpression.WhenFalse);
            Assert.Equal("C", falseBranchTypeInfo.Type.ToTestDisplayString());
            Assert.Equal("C", falseBranchTypeInfo.ConvertedType.ToTestDisplayString());
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81021")]
        public void ErrorRecovery_VariableDeclaration()
        {
            var source = """
                class C
                {
                    void M(bool b)
                    {
                        C c = b ? new(a) : default;
                    }