Assert that equivalences groups are ordered.

Bug: 172194101
Change-Id: I8524db0cd0e90dbdd13859c124bd8ff24261a211
diff --git a/src/main/java/com/android/tools/r8/synthesis/SyntheticFinalization.java b/src/main/java/com/android/tools/r8/synthesis/SyntheticFinalization.java
index 8aaeeb9..fe1c8fa 100644
--- a/src/main/java/com/android/tools/r8/synthesis/SyntheticFinalization.java
+++ b/src/main/java/com/android/tools/r8/synthesis/SyntheticFinalization.java
@@ -360,6 +360,9 @@
           groups.sort(EquivalenceGroup::compareTo);
           for (int i = 0; i < groups.size(); i++) {
             EquivalenceGroup<T> group = groups.get(i);
+            // Two equivalence groups in same context type must be distinct otherwise the assignment
+            // of the synthetic name will be non-deterministic between the two.
+            assert i == 0 || checkGroupsAreDistict(groups.get(i - 1), group);
             DexType representativeType = createExternalType(context, i, factory);
             equivalences.put(representativeType, group);
           }
@@ -389,6 +392,12 @@
     return groups;
   }
 
+  private static <T extends SyntheticDefinition & Comparable<T>> boolean checkGroupsAreDistict(
+      EquivalenceGroup<T> g1, EquivalenceGroup<T> g2) {
+    assert g1.compareTo(g2) != 0;
+    return true;
+  }
+
   private static <T extends SyntheticDefinition & Comparable<T>> T findDeterministicRepresentative(
       List<T> members) {
     // Pick a deterministic member as representative.