diff --git a/build.gradle.kts b/build.gradle.kts index 3c3edfc..1d30f05 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,6 +22,10 @@ tasks.test { } kotlin { jvmToolchain(23) + compilerOptions { + allWarningsAsErrors.set(true) + freeCompilerArgs.add("-Xreturn-value-checker=full") + } } tasks.withType().configureEach { diff --git a/src/main/kotlin/kodvent/collections/MapExtensions.kt b/src/main/kotlin/kodvent/collections/MapExtensions.kt index 1af3660..a93f5e1 100644 --- a/src/main/kotlin/kodvent/collections/MapExtensions.kt +++ b/src/main/kotlin/kodvent/collections/MapExtensions.kt @@ -36,6 +36,7 @@ public fun MutableMap.increment(key: T) { * @sample samples.IncrementAndDecrementSamples.decrementBasicUsage * @sample samples.IncrementAndDecrementSamples.decrementInventoryManagement */ +@IgnorableReturnValue public fun MutableMap.decrement(key: T): Boolean { val count = this[key] ?: return false if (count > 1) { diff --git a/src/main/kotlin/kodvent/datastructures/DisjointSetUnion.kt b/src/main/kotlin/kodvent/datastructures/DisjointSetUnion.kt index baf0fbd..7be7f6a 100644 --- a/src/main/kotlin/kodvent/datastructures/DisjointSetUnion.kt +++ b/src/main/kotlin/kodvent/datastructures/DisjointSetUnion.kt @@ -87,6 +87,7 @@ public class DisjointSetUnion(size: Int) { * @sample samples.DisjointSetUnionSamples.basicUsage * @sample samples.DisjointSetUnionSamples.detectingCycles */ + @IgnorableReturnValue public fun union(x: Int, y: Int): Boolean { val rootX = find(x) val rootY = find(y) @@ -159,7 +160,9 @@ public class DisjointSetUnion(size: Int) { throw IndexOutOfBoundsException("Element ($x) is out of disjoint set bounds: [0, ${parent.size})") } - parent.indices.forEach { find(it) } + for (i in parent.indices) { + parent[i] = find(i) + } val oldRoot = parent[x] val elementsInSet = parent.indices.filter { parent[it] == oldRoot } diff --git a/src/test/kotlin/kodvent/datastructures/DisjointSetUnionTest.kt b/src/test/kotlin/kodvent/datastructures/DisjointSetUnionTest.kt index 04b2f31..50bcb48 100644 --- a/src/test/kotlin/kodvent/datastructures/DisjointSetUnionTest.kt +++ b/src/test/kotlin/kodvent/datastructures/DisjointSetUnionTest.kt @@ -494,8 +494,9 @@ class DisjointSetUnionTest { dsu.union(5, 6) // Trigger path compression by finding a deep element - dsu.find(6) - dsu.find(0) + val root6BeforeIsolate = dsu.find(6) + val root0BeforeIsolate = dsu.find(0) + assertEquals(root6BeforeIsolate, root0BeforeIsolate, "All elements should share the same root before isolate(3)") // Now isolate element 3 dsu.isolate(3)