提交 84eb1010 编写于 作者: L Llewellyn Pritchard

Fixes #7878

上级 bb0ff321
......@@ -225,6 +225,7 @@ internal override ImmutableArray<NamedTypeSymbol> GetDeclaredInterfaces(ConsList
var baseInterfaces = ArrayBuilder<NamedTypeSymbol>.GetInstance();
NamedTypeSymbol baseType = null;
SourceLocation baseTypeLocation = null;
foreach (var decl in this.declaration.Declarations)
{
......@@ -238,18 +239,21 @@ internal override ImmutableArray<NamedTypeSymbol> GetDeclaredInterfaces(ConsList
if ((object)baseType == null)
{
baseType = partBase;
baseTypeLocation = decl.NameLocation;
}
else if (baseType.TypeKind == TypeKind.Error && (object)partBase != null)
{
// if the old base was an error symbol, copy it to the interfaces list so it doesn't get lost
partInterfaces = partInterfaces.Add(baseType);
baseType = partBase;
baseTypeLocation = decl.NameLocation;
}
else if ((object)partBase != null && partBase != baseType && partBase.TypeKind != TypeKind.Error)
{
// the parts do not agree
var info = diagnostics.Add(ErrorCode.ERR_PartialMultipleBases, Locations[0], this);
baseType = new ExtendedErrorTypeSymbol(baseType, LookupResultKind.Ambiguous, info);
baseTypeLocation = decl.NameLocation;
reportedPartialConflict = true;
}
}
......@@ -273,7 +277,7 @@ internal override ImmutableArray<NamedTypeSymbol> GetDeclaredInterfaces(ConsList
if ((object)baseType != null && baseType.IsStatic)
{
// '{1}': cannot derive from static class '{0}'
diagnostics.Add(ErrorCode.ERR_StaticBaseClass, Locations[0], baseType, this);
diagnostics.Add(ErrorCode.ERR_StaticBaseClass, baseTypeLocation ?? Locations[0], baseType, this);
}
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
......@@ -281,7 +285,7 @@ internal override ImmutableArray<NamedTypeSymbol> GetDeclaredInterfaces(ConsList
if ((object)baseType != null && !this.IsNoMoreVisibleThan(baseType, ref useSiteDiagnostics))
{
// Inconsistent accessibility: base class '{1}' is less accessible than class '{0}'
diagnostics.Add(ErrorCode.ERR_BadVisBaseClass, Locations[0], this, baseType);
diagnostics.Add(ErrorCode.ERR_BadVisBaseClass, baseTypeLocation ?? Locations[0], this, baseType);
}
var baseInterfacesRO = baseInterfaces.ToImmutableAndFree();
......
......@@ -338,6 +338,63 @@ public class E : C.X { }
);
}
[Fact, WorkItem(7878, "https://github.com/dotnet/roslyn/issues/7878")]
public void BadVisibilityPartial()
{
var text = @"
internal class NV
{
}
public partial class C1
{
}
partial class C1 : NV
{
}
public partial class C1
{
}
";
var comp = CreateCompilationWithMscorlib(text);
comp.VerifyDiagnostics(
// (10,15): error CS0060: Inconsistent accessibility: base class 'NV' is less accessible than class 'C1'
// partial class C1 : NV
Diagnostic(ErrorCode.ERR_BadVisBaseClass, "C1").WithArguments("C1", "NV").WithLocation(10, 15));
}
[Fact, WorkItem(7878, "https://github.com/dotnet/roslyn/issues/7878")]
public void StaticBasePartial()
{
var text = @"
static class NV
{
}
public partial class C1
{
}
partial class C1 : NV
{
}
public partial class C1
{
}
";
var comp = CreateCompilationWithMscorlib(text);
comp.VerifyDiagnostics(
// (10,15): error CS0709: 'C1': cannot derive from static class 'NV'
// partial class C1 : NV
Diagnostic(ErrorCode.ERR_StaticBaseClass, "C1").WithArguments("NV", "C1").WithLocation(10, 15),
// (10,15): error CS0060: Inconsistent accessibility: base class 'NV' is less accessible than class 'C1'
// partial class C1 : NV
Diagnostic(ErrorCode.ERR_BadVisBaseClass, "C1").WithArguments("C1", "NV").WithLocation(10, 15));
}
[Fact]
public void EricLiCase1()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册