Skip to content

Commit

Permalink
Backport fix for K2 (arrow-kt#3098)
Browse files Browse the repository at this point in the history
  • Loading branch information
serras authored and kyay10 committed Aug 18, 2023
1 parent 0bfe55c commit 2142eb2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ public value class NonEmptySet<out A> private constructor(
override fun toString(): String = "NonEmptySet(${this.joinToString()})"

@Suppress("RESERVED_MEMBER_INSIDE_VALUE_CLASS")
override fun equals(other: Any?): Boolean = when (other) {
is NonEmptySet<*> -> elements == other.elements
else -> elements == other
}
override fun equals(other: Any?): Boolean =
elements == other

@Suppress("RESERVED_MEMBER_INSIDE_VALUE_CLASS")
override fun hashCode(): Int =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class NonEmptySetTest : StringSpec({
val initialSet: NonEmptySet<Int> = nonEmptySetOf(element) + Arb.nonEmptySet(Arb.int()).next()
initialSet.plus(element) shouldBe initialSet
}

"NonEmptySet equals Set" {
checkAll(
Arb.nonEmptySet(Arb.int())
Expand All @@ -49,5 +50,17 @@ class NonEmptySetTest : StringSpec({
}
}
}

"NonEmptySet equals NonEmptySet" {
checkAll(
Arb.nonEmptySet(Arb.int())
) { nes ->
val s = nes.toSet().toNonEmptySetOrNull()!!
withClue("$nes should be equal to $s") {
(nes == s).shouldBeTrue() // `shouldBe` doesn't use the `equals` methods on `Iterable`
nes.hashCode() shouldBe s.hashCode()
}
}
}
})

0 comments on commit 2142eb2

Please sign in to comment.