Skip to content

Commit 88832fb

Browse files
authored
[ApiCompat] Warn if abstract keyword is removed from member (#46797)
1 parent cbd3ca0 commit 88832fb

File tree

16 files changed

+78
-42
lines changed

16 files changed

+78
-42
lines changed

src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompatibility/Resources.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@
186186
<data name="CannotAddVirtualToMember" xml:space="preserve">
187187
<value>Cannot add virtual keyword to member '{0}'.</value>
188188
</data>
189-
<data name="CannotRemoveVirtualFromMember" xml:space="preserve">
190-
<value>Cannot remove virtual keyword from member '{0}'.</value>
189+
<data name="CannotRemoveVirtualOrAbstractFromMember" xml:space="preserve">
190+
<value>Cannot remove '{0}' keyword from member '{1}'.</value>
191191
</data>
192192
<data name="ApiCompatibilityHeader" xml:space="preserve">
193193
<value>API compatibility errors between '{0}' ({2}) and '{1}' ({3}):</value>

src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompatibility/Rules/CannotAddOrRemoveVirtualKeyword.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private void RunOnMemberSymbol(ISymbol? left, ISymbol? right, ITypeSymbol leftCo
6363
leftMetadata,
6464
rightMetadata,
6565
DiagnosticIds.CannotRemoveVirtualFromMember,
66-
string.Format(Resources.CannotRemoveVirtualFromMember, left),
66+
string.Format(Resources.CannotRemoveVirtualOrAbstractFromMember, "virtual", left),
6767
DifferenceType.Removed,
6868
right));
6969
}
@@ -86,6 +86,21 @@ private void RunOnMemberSymbol(ISymbol? left, ISymbol? right, ITypeSymbol leftCo
8686
right));
8787
}
8888
}
89+
90+
if (left.IsAbstract)
91+
{
92+
if (!right.IsAbstract && !right.IsVirtual)
93+
{
94+
// abstract can be made virtual but cannot remove abstract.
95+
differences.Add(new CompatDifference(
96+
leftMetadata,
97+
rightMetadata,
98+
DiagnosticIds.CannotRemoveVirtualFromMember,
99+
string.Format(Resources.CannotRemoveVirtualOrAbstractFromMember, "abstract", left),
100+
DifferenceType.Removed,
101+
right));
102+
}
103+
}
89104
}
90105
}
91106
}

src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompatibility/xlf/Resources.cs.xlf

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompatibility/xlf/Resources.de.xlf

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompatibility/xlf/Resources.es.xlf

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompatibility/xlf/Resources.fr.xlf

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompatibility/xlf/Resources.it.xlf

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompatibility/xlf/Resources.ja.xlf

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompatibility/xlf/Resources.ko.xlf

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompatibility/xlf/Resources.pl.xlf

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)