Repository: dotnet/roslyn
File: src/Compilers/CSharp/Test/Symbol/Symbols/GenericConstraintTests.cs (C#)

Code before:

            var tree = comp.SyntaxTrees.Single();
            var model = comp.GetSemanticModel(tree);
            var nest = tree.GetRoot().DescendantNodes().OfType<IdentifierNameSyntax>().Where(i => i.Identifier.ValueText == "Nest").Single();
            Assert.Null(model.GetAliasInfo(nest));
            Assert.Equal("Base.Nest", model.GetTypeInfo(nest).Type.ToDisplayString());
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41733")]
        public void TypeParameter_BaseType_ReturnsNull()
        {
            var source = """
                abstract class Base
                {
                    public abstract void Method();
                }

                class Derived<T> where T : Base
                {
                }
                """;
            var comp = CreateCompilation(source);
            comp.VerifyDiagnostics();

            var derivedType = comp.GetTypeByMetadataName("Derived`1");
            Assert.NotNull(derivedType);

            var typeParameter = derivedType.TypeParameters[0];
            Assert.NotNull(typeParameter);

            var publicTypeParameter = (ITypeParameterSymbol)typeParameter.GetPublicSymbol();
            Assert.Null(publicTypeParameter.BaseType);
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41733")]
        public void MethodTypeParameter_BaseType_ReturnsNull()
        {
            var source = """
                class C
                {
                    void M<T>() where T : class
                    {
                    }
                }
                """;
            var comp = CreateCompilation(source);
            comp.VerifyDiagnostics();

            var type = comp.GetTypeByMetadataName("C");
            Assert.NotNull(type);


Review comment (suggestion):
The tests are unnecessarily verbose. There's no benefit to those intermediary assertions. There's only one thing this test is intended to check, the final assertion in the test. #Closed

Code after:

            var tree = comp.SyntaxTrees.Single();
            var model = comp.GetSemanticModel(tree);
            var nest = tree.GetRoot().DescendantNodes().OfType<IdentifierNameSyntax>().Where(i => i.Identifier.ValueText == "Nest").Single();
            Assert.Null(model.GetAliasInfo(nest));
            Assert.Equal("Base.Nest", model.GetTypeInfo(nest).Type.ToDisplayString());
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41733")]
        public void TypeParameter_BaseType_ReturnsNull()
        {
            var source = """
                abstract class Base
                {
                    public abstract void Method();
                }

                class Derived<T> where T : Base
                {
                }
                """;
            var comp = CreateCompilation(source);
            comp.VerifyDiagnostics();

            var typeParameter = (ITypeParameterSymbol)comp.GetTypeByMetadataName("Derived`1").TypeParameters[0].GetPublicSymbol();
            Assert.Null(typeParameter.BaseType);
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41733")]
        public void MethodTypeParameter_BaseType_ReturnsNull()
        {
            var source = """
                class C
                {
                    void M<T>() where T : class
                    {
                    }
                }
                """;
            var comp = CreateCompilation(source);
            comp.VerifyDiagnostics();

            var typeParameter = (ITypeParameterSymbol)comp.GetTypeByMetadataName("C").GetMethod("M").TypeParameters[0].GetPublicSymbol();
            Assert.Null(typeParameter.BaseType);
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41733")]
        public void ObjectType_BaseType_ReturnsNull()
        {
            var comp = CreateCompilation("");
            comp.VerifyDiagnostics();