Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Loosen assertEquals type constraint to allow subtyping #35

Closed
olafurpg opened this issue Feb 2, 2020 · 2 comments
Closed

Loosen assertEquals type constraint to allow subtyping #35

olafurpg opened this issue Feb 2, 2020 · 2 comments

Comments

@olafurpg
Copy link
Member

olafurpg commented Feb 2, 2020

Context: https://gitter.im/scalameta/munit?at=5e36e5cadc52c34ace3fd552

Currently, the following code does not typecheck

assertEquals(List(1).headOption, Some(1))
// Cannot prove that Option[Int] =:= Some[Int]

We might want to allow the right-hand side (expected value) to be a subtype of the right hand side

assertEquals(List(1).headOption, Some(1)) // OK
assertEquals(Some(1), List(1).headOption) // ERROR: Cannot prove that Option[Int] <:< Some[Int]

The reasoning being that the expected value is often a hardcoded expression like "Some(1)" while the obtained value comes from a generic method implementation.

@olafurpg
Copy link
Member Author

I'm gonna close this as wontfix. If there is demand, I'm open to add a new assertAnyEquals() helpers that takes Any arguments so that it's possible to for example compare Left[Int, Nothing] with Either[Int, Nothing] but it's not a method that I have found the need for so far.

@olafurpg
Copy link
Member Author

Implemented this change in #70. @gabro also found a nice workaround when you really want to compare different types: assertEquals[Any, Any](a, b)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant