提交 2a0ac086 编写于 作者: K Karlo 提交者: AlekseyTs

Fix #19002 Error CS0503 shows the correct modifier target (#19025)

* Error CS0503 shows the correct modifier target
上级 217f6506
......@@ -179,7 +179,7 @@ internal class CSharpResources {
}
/// <summary>
/// Looks up a localized string similar to The abstract method &apos;{0}&apos; cannot be marked virtual.
/// Looks up a localized string similar to The abstract {0} &apos;{1}&apos; cannot be marked virtual.
/// </summary>
internal static string ERR_AbstractNotVirtual {
get {
......
......@@ -1422,7 +1422,7 @@ If such a class is used as a base class and if the deriving class defines a dest
<value>'{0}' cannot be both abstract and sealed</value>
</data>
<data name="ERR_AbstractNotVirtual" xml:space="preserve">
<value>The abstract method '{0}' cannot be marked virtual</value>
<value>The abstract {0} '{1}' cannot be marked virtual</value>
</data>
<data name="ERR_StaticConstant" xml:space="preserve">
<value>The constant '{0}' cannot be marked static</value>
......
......@@ -485,7 +485,7 @@ protected void CheckModifiersAndType(DiagnosticBag diagnostics)
}
else if (IsAbstract && IsVirtual)
{
diagnostics.Add(ErrorCode.ERR_AbstractNotVirtual, location, this);
diagnostics.Add(ErrorCode.ERR_AbstractNotVirtual, location, this.Kind.Localize(), this);
}
else if (ContainingType.IsSealed && this.DeclaredAccessibility.HasProtected() && !this.IsOverride)
{
......
......@@ -940,7 +940,7 @@ private void CheckModifiers(Location location, DiagnosticBag diagnostics)
}
else if (IsAbstract && IsVirtual)
{
diagnostics.Add(ErrorCode.ERR_AbstractNotVirtual, location, this);
diagnostics.Add(ErrorCode.ERR_AbstractNotVirtual, location, this.Kind.Localize(), this);
}
else if (IsAbstract && ContainingType.TypeKind == TypeKind.Struct)
{
......
......@@ -848,7 +848,7 @@ private void CheckModifiers(Location location, bool isIndexer, DiagnosticBag dia
}
else if (IsAbstract && IsVirtual)
{
diagnostics.Add(ErrorCode.ERR_AbstractNotVirtual, location, this);
diagnostics.Add(ErrorCode.ERR_AbstractNotVirtual, location, this.Kind.Localize(), this);
}
else if (ContainingType.IsSealed && this.DeclaredAccessibility.HasProtected() && !this.IsOverride)
{
......
......@@ -7746,7 +7746,7 @@ abstract public class cly : clx
[Fact]
public void CS0503ERR_AbstractNotVirtual01()
{
var text = @"namespace NS
var source = @"namespace NS
{
abstract public class clx
{
......@@ -7757,14 +7757,24 @@ abstract public class clx
} // class clx
}
";
var comp = DiagnosticsUtils.VerifyErrorsAndGetCompilationWithMscorlib(text,
new ErrorDescription { Code = (int)ErrorCode.ERR_AbstractNotVirtual, Line = 5, Column = 40 },
new ErrorDescription { Code = (int)ErrorCode.ERR_AbstractNotVirtual, Line = 6, Column = 41 },
new ErrorDescription { Code = (int)ErrorCode.ERR_AbstractNotVirtual, Line = 7, Column = 40 },
new ErrorDescription { Code = (int)ErrorCode.ERR_AbstractNotVirtual, Line = 8, Column = 53 });
var ns = comp.SourceModule.GlobalNamespace.GetMembers("NS").Single() as NamespaceSymbol;
// TODO...
var comp = CreateStandardCompilation(source).VerifyDiagnostics(
// (7,40): error CS0503: The abstract property 'clx.P' cannot be marked virtual
// virtual abstract public object P { get; set; }
Diagnostic(ErrorCode.ERR_AbstractNotVirtual, "P").WithArguments("property", "NS.clx.P").WithLocation(7, 40),
// (6,41): error CS0503: The abstract method 'clx.M2<T>(T)' cannot be marked virtual
// abstract virtual protected void M2<T>(T t);
Diagnostic(ErrorCode.ERR_AbstractNotVirtual, "M2").WithArguments("method", "NS.clx.M2<T>(T)").WithLocation(6, 41),
// (5,40): error CS0503: The abstract method 'clx.M1()' cannot be marked virtual
// abstract virtual internal void M1();
Diagnostic(ErrorCode.ERR_AbstractNotVirtual, "M1").WithArguments("method", "NS.clx.M1()").WithLocation(5, 40),
// (8,53): error CS0503: The abstract event 'clx.E' cannot be marked virtual
// virtual abstract public event System.Action E;
Diagnostic(ErrorCode.ERR_AbstractNotVirtual, "E").WithArguments("event", "NS.clx.E").WithLocation(8, 53));
var nsNamespace = comp.SourceModule.GlobalNamespace.GetMembers("NS").Single() as NamespaceSymbol;
var clxClass = nsNamespace.GetMembers("clx").Single() as NamedTypeSymbol;
Assert.Equal(9, clxClass.GetMembers().Length);
}
[Fact]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册