Skip to content

Commit

Permalink
Disable two assertions for j2kt that are only passing by accident
Browse files Browse the repository at this point in the history
The implementation code expects `Comparable` implementations to throw
`ClassCastException`s when trying to compare to objects of the wrong type.

Kotlin/Native `Comparable`s don’t make this guarantee yet (This is expected to
change when https://youtrack.jetbrains.com/issue/KT-71001/ is fixed).

The assertions are preventing us from making a compiler flag change that changes
the behavior that made these assertions pass accidentally.

PiperOrigin-RevId: 725264702
  • Loading branch information
martinkretzschmar authored and Google Java Core Libraries committed Feb 10, 2025
1 parent ca73f71 commit 8ea070f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ public void testContains() {
assertTrue(set.contains(2));
assertTrue(set.contains(3));
assertFalse(set.contains(4));
}

// TODO: https://youtrack.jetbrains.com/issue/KT-71001/ - Enable when Kotlin throws expected CCE.
@J2ktIncompatible
public void testContains_typeMismatch() {
ImmutableSortedSet<Integer> set = ContiguousSet.create(Range.open(0, 4), integers());
assertFalse(set.contains((Object) "blah"));
}

Expand All @@ -291,6 +297,12 @@ public void testContainsAll() {
for (Set<Integer> subset : Sets.powerSet(ImmutableSet.of(1, 2, 3))) {
assertFalse(set.containsAll(Sets.union(subset, ImmutableSet.of(9))));
}
}

// TODO: https://youtrack.jetbrains.com/issue/KT-71001/ - Enable when Kotlin throws expected CCE.
@J2ktIncompatible
public void testContainsAll_typeMismatch() {
ImmutableSortedSet<Integer> set = ContiguousSet.create(Range.closed(1, 3), integers());
assertFalse(set.containsAll((Collection<?>) ImmutableSet.of("blah")));
}

Expand Down
12 changes: 12 additions & 0 deletions guava-tests/test/com/google/common/collect/ContiguousSetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ public void testContains() {
assertTrue(set.contains(2));
assertTrue(set.contains(3));
assertFalse(set.contains(4));
}

// TODO: https://youtrack.jetbrains.com/issue/KT-71001/ - Enable when Kotlin throws expected CCE.
@J2ktIncompatible
public void testContains_typeMismatch() {
ImmutableSortedSet<Integer> set = ContiguousSet.create(Range.open(0, 4), integers());
assertFalse(set.contains((Object) "blah"));
}

Expand All @@ -291,6 +297,12 @@ public void testContainsAll() {
for (Set<Integer> subset : Sets.powerSet(ImmutableSet.of(1, 2, 3))) {
assertFalse(set.containsAll(Sets.union(subset, ImmutableSet.of(9))));
}
}

// TODO: https://youtrack.jetbrains.com/issue/KT-71001/ - Enable when Kotlin throws expected CCE.
@J2ktIncompatible
public void testContainsAll_typeMismatch() {
ImmutableSortedSet<Integer> set = ContiguousSet.create(Range.closed(1, 3), integers());
assertFalse(set.containsAll((Collection<?>) ImmutableSet.of("blah")));
}

Expand Down

0 comments on commit 8ea070f

Please sign in to comment.