-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strict equality is too strict in Scala 3.5 #819
Comments
@EugeneFlesselle notes that in Scala 3, we could move the implicit parameters list to solve the issue in this specific use case: def assertEquals2[A, B](using loc: Location, compare: Compare[A, B])(
obtained: A,
expected: B,
clue: => Any = "values are not the same"
): Unit = assertEquals(obtained, expected, clue) Note sure this would be a general fix though. |
Thanks for reporting! Isn't this expected though? I don't the exact background behind strictEquality, but since Set is invariant I would assume sets of different types are indeed not comparable. If needed we can include the proposed fix, but I am not sure about what cases the current behaviour would be problematic in. |
That depends on your expectations of type inference.
|
That's a tough one, I imagine both bahaviours to be expected at times:
Wouldn't the current behaviour in 3.5 be actually safer? If you want to be explicit you can cast the set of birds to animals. On (third?) hand we will make it work with Lists, but they are covariant, so this is expected. |
Yeah, that's similar to our use-case. I find it reasonable to want to test the return value of method whose return type is defined in terms of an interface (as That said, it's worth noting that the current MUnit behavior is in line with Scala's strict equality, so that might be okay. //> using dep org.scalameta::munit::1.0.1
trait Interface
case class Impl() extends Interface
def foo(): Set[Interface] = Set(Impl())
class FooTest extends munit.FunSuite:
val s = Set(2)
test("foo (normal equality)"):
assert(foo() == Set(Impl())) // Works in Scala 3.3 and 3.5
test("foo (strict equality)"):
import scala.language.strictEquality
assert(foo() == Set(Impl())) // Fails in Scala 3.3 and 3.5
test("foo (assertEquals)"):
assertEquals(foo(), Set(Impl())) // Works in Scala 3.3, fails in Scala 3.5 |
Wait. Seeing that there is a
|
In case there is a special type class for Scala itself, we could do the same, which would allow us not to change interfaces 🤔 |
In Scala 3.5,
assertEquals
doesn't enable to compareSet
of different types:This is because in 3.5, the
B
type parameter ofassertEquals
is inferred to beSet[Int]
instead ofSet[Any]
as in 3.3assertEquals
's signature:munit/munit/shared/src/main/scala/munit/Assertions.scala
Lines 91 to 95 in b02ef31
Instances of
Compare
are defined as:munit/munit/shared/src/main/scala/munit/Compare.scala
Lines 104 to 108 in b02ef31
munit/munit/shared/src/main/scala/munit/Compare.scala
Lines 116 to 120 in b02ef31
The text was updated successfully, but these errors were encountered: