[mono-api-html] Make --ignore-changes-virtual less lenient.
authorJonathan Pryor <jonpryor@vt.edu>
Thu, 13 Nov 2014 18:02:34 +0000 (13:02 -0500)
committerJonathan Pryor <jonpryor@vt.edu>
Thu, 13 Nov 2014 18:36:45 +0000 (13:36 -0500)
As mentioned in commit 789517f8, the intentino of
`mono-api-html --ignore-changes-virtual` is so that when a method is
changed from non-virtual to virtual or override, or from virtual to
override, a "Removed member" message isn't triggered.

However, the previous implementation was too lenient. While *adding*
virtual to the method is fine, *removing* is NOT fine, as that would
be an API breaking change (e.g. all classes which attempt to override
a previously virtual method could no longer do so).

Make the virtual check stricter so that virtual/override to
non-virtual changes are not ignored.

mcs/tools/corcompare/mono-api-html/ConstructorComparer.cs
mcs/tools/corcompare/mono-api-html/MemberComparer.cs

index eae249a205893efc915fddbc939f44cb62a6045c..66dfeb004375965a77add19d7abd98754e5e53a5 100644 (file)
@@ -62,7 +62,7 @@ namespace Xamarin.ApiDiff {
 
                                if ((attr & MethodAttributes.Static) != 0) {
                                        sb.Append ("static ");
-                               } else if ((attr & MethodAttributes.Virtual) != 0 && !State.IgnoreVirtualChanges) {
+                               } else if ((attr & MethodAttributes.Virtual) != 0) {
                                        if ((attr & MethodAttributes.VtableLayoutMask) == 0)
                                                sb.Append ("override ");
                                        else
index 0a646c7a2a26f392cacef89ef548c252f4aa28c1..cc2e944fc010092d4de29b75e4bf84ae9644e3ef 100644 (file)
@@ -177,7 +177,18 @@ namespace Xamarin.ApiDiff {
                        if (base.Equals (source, target))
                                return true;
 
-                       return GetDescription (source) == GetDescription (target);
+                       string sourceDescription = GetDescription (source);
+                       string targetDescription = GetDescription (target);
+
+                       return (sourceDescription == targetDescription) ||
+                               // *adding* virtual or override to target is acceptable; *removing* them is NOT
+                               (State.IgnoreVirtualChanges &&
+                                       // non-virtual to virtual is fine
+                                       (sourceDescription == targetDescription.Replace ("virtual ", "")) ||
+                                       // non-virtual to override is fine
+                                       (sourceDescription == targetDescription.Replace ("override ", "")) ||
+                                       // virtual to override is fine
+                                       (sourceDescription.Replace (" virtual ", " override ") == targetDescription));
                }
 
                bool IsNowObsoleted (XElement source, XElement target)