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

Code before:
        [Fact]
        public void TestBadContainedTypeVisibility()
        {
            var source = @"
public class A { internal class B { } }
public class C : A.B { }";

            var comp = CreateCompilation(source);
            comp.VerifyDiagnostics(
                // (3,14): error CS0060: Inconsistent accessibility: base class 'A.B' is less accessible than class 'C'
                //     public class C : A.B { }
                Diagnostic(ErrorCode.ERR_BadVisBaseClass, "C").WithArguments("C", "A.B").WithLocation(3, 14));
        }

        [Fact]
        public void TestBadContainingTypeVisibility()
        {
            var source = @"
class A { public class B { } }
public class C : A.B { }";

            var comp = CreateCompilation(source);
            comp.VerifyDiagnostics(
                // (3,14): error CS9335: Inconsistent accessibility: type 'A' is less accessible than class 'C'
                //     public class C : A.B { }
                Diagnostic(ErrorCode.ERR_BadVisBaseType, "C").WithArguments("C", "A").WithLocation(3, 14));
        }

        [Fact]
        public void TestBadContainingTypeVisibilityWithoutExplicitReference()
        {
            var source = @"
using static A;

static class A
{
    public class B { }
}

public class C : B { }";

            var comp = CreateCompilation(source);
            comp.VerifyDiagnostics(
                // (9,14): error CS9335: Inconsistent accessibility: type 'A' is less accessible than class 'C' 
                //     public class C : B { }
                Diagnostic(ErrorCode.ERR_BadVisBaseType, "C").WithArguments("C", "A").WithLocation(9, 14));
        }
    }
}


Review comment (suggestion):
I'm wondering whether the message could be improved - since we squiggle the class `C` itself, the user might be confused where to search for the less accessible type (in nested types, in members, in base types, in attributes, ...) - i.e., should the message be something like this?

"Inconsistent accessibility: type A which appears in the base type is less accessible than class C"

Code after:
        [Fact]
        public void TestBadContainedTypeVisibility()
        {
            var source = @"
public class A { internal class B { } }
public class C : A.B { }";

            var comp = CreateCompilation(source);
            comp.VerifyDiagnostics(
                // (3,14): error CS0060: Inconsistent accessibility: base class 'A.B' is less accessible than class 'C'
                //     public class C : A.B { }
                Diagnostic(ErrorCode.ERR_BadVisBaseClass, "C").WithArguments("C", "A.B").WithLocation(3, 14));
        }

        [Fact]
        public void TestBadContainingTypeVisibility()
        {
            var source = @"
class A { public class B { } }
public class C : A.B { }";

            var comp = CreateCompilation(source);
            comp.VerifyDiagnostics(
                // (3,14): error CS9338: Inconsistent accessibility: type 'A' is less accessible than class 'C'
                //     public class C : A.B { }
                Diagnostic(ErrorCode.ERR_BadVisBaseType, "C").WithArguments("C", "A").WithLocation(3, 14));
        }

        [Fact]
        public void TestBadContainingTypeVisibilityWithoutExplicitReference()
        {
            var source = @"
using static A;

static class A
{
    public class B { }
}

public class C : B { }";

            var comp = CreateCompilation(source);
            comp.VerifyDiagnostics(
                // (9,14): error CS9338: Inconsistent accessibility: type 'A' is less accessible than class 'C' 
                //     public class C : B { }
                Diagnostic(ErrorCode.ERR_BadVisBaseType, "C").WithArguments("C", "A").WithLocation(9, 14));
        }
    }
}