scalameta / munit

Scala testing library with actionable errors and extensible APIs
https://scalameta.org/munit
Apache License 2.0
428 stars 88 forks source link

When using singleton types `assertEquals` does not work but `==` does #770

Open hmf opened 4 months ago

hmf commented 4 months ago

Using veersion 3.4.2-RC1.

I have the following definitions that implement a map version of an HList:

sealed trait IMap:
case object IEmpT extends IMap
case class ICons[K, V, T <: IMap](key: K, value: V, tail: T) extends IMap

The following non-commented code compiles in Scala 3 (3.4.2-RC1):

    val ff1b: ICons["5", 5, IEmpT] = ICons("5", 5, IEmpT)
    summon[ff1b.type <:< ICons["5", 5,IEmpT]]
    // summon[ICons["5", 5,IEmpT] =:= ff1b.type] // fails
    // summon[ICons["5", 5,IEmpT] <:< ff1b.type] // fails

The commented code above fails. I can compare the values with == without any problem as shown below:

    assert(ICons("5", 5,IEmpT) == ff1b) // Ok
    assert(ff1b == ICons("5", 5,IEmpT)) // Ok
    assert(ff1b.isInstanceOf[ICons[String, Int, IEmpT]])

However the following fails to compile with errors shown at the end:

    assertEquals(ICons("5", 5,IEmpT), ff1b)
    assertEquals(ff1b, ICons("5", 5,IEmpT))

Because == works, I would assume that the assertEquals above should also work, but it do not. Looking at this code it seems it should work. Indeed, when I don't use singleton types, it does. However ComparePriority1 and ComparePriority2 don't seem to be working as expected.

Is this expected?

TIA

[error] 608 |    assertEquals(ICons("5", 5,IEmpT), ff1b)
[error]     |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]     |Can't compare these two types:
[error]     |  First type:  icollection.IMap.ICons[String, Int, icollection.IMap.IEmpT.type]
[error]     |  Second type: icollection.IMap.ICons[("5" : String), (5 : Int), icollection.IMap.IEmpT]
[error]     |Possible ways to fix this error:
[error]     |  Alternative 1: provide an implicit instance for Compare[icollection.IMap.ICons[String, Int, icollection.IMap.IEmpT.type], icollection.IMap.ICons[("5" : String), (5 : Int), icollection.IMap.IEmpT]]
[error]     |  Alternative 2: upcast either type into `Any` or a shared supertype.
[error]     |I found:
[error]     |
[error]     |    munit.Compare.compareSubtypeWithSupertype[
[error]     |      icollection.IMap.ICons[String, Int, icollection.IMap.IEmpT.type],
[error]     |      icollection.IMap.ICons[("5" : String), (5 : Int), icollection.IMap.IEmpT]](
[error]     |      /* missing */
[error]     |        summon[icollection.IMap.ICons[String, Int, icollection.IMap.IEmpT.type] <:<
[error]     |          icollection.IMap.ICons[("5" : String), (5 : Int), icollection.IMap.IEmpT]]
[error]     |      )
[error]     |
[error]     |But no implicit values were found that match type icollection.IMap.ICons[String, Int, icollection.IMap.IEmpT.type] <:<
[error]     |  icollection.IMap.ICons[("5" : String), (5 : Int), icollection.IMap.IEmpT].
[error] -- [E172] Type Error: /home/hmf/VSCodeProjects/sploty/meta/test/src/icollection/IMapSpec.scala:609:16 
[error] 609 |    assertEquals(ff1b, ICons("5", 5,IEmpT))
[error]     |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]     |Can't compare these two types:
[error]     |  First type:  icollection.IMap.ICons[("5" : String), (5 : Int), icollection.IMap.IEmpT]
[error]     |  Second type: icollection.IMap.ICons[String, Int, icollection.IMap.IEmpT.type]
[error]     |Possible ways to fix this error:
[error]     |  Alternative 1: provide an implicit instance for Compare[icollection.IMap.ICons[("5" : String), (5 : Int), icollection.IMap.IEmpT], icollection.IMap.ICons[String, Int, icollection.IMap.IEmpT.type]]
[error]     |  Alternative 2: upcast either type into `Any` or a shared supertype.
[error]     |I found:
[error]     |
[error]     |    munit.Compare.compareSubtypeWithSupertype[
[error]     |      icollection.IMap.ICons[("5" : String), (5 : Int), icollection.IMap.IEmpT],
[error]     |      icollection.IMap.ICons[String, Int, icollection.IMap.IEmpT.type]](
[error]     |      /* missing */
[error]     |        summon[
[error]     |          icollection.IMap.ICons[("5" : String), (5 : Int), icollection.IMap.IEmpT]
[error]     |          <:< icollection.IMap.ICons[String, Int, icollection.IMap.IEmpT.type]]
[error]     |    )
[error]     |
[error]     |But no implicit values were found that match type icollection.IMap.ICons[("5" : String), (5 : Int), icollection.IMap.IEmpT] <:<
[error]     |  icollection.IMap.ICons[String, Int, icollection.IMap.IEmpT.type].
[warn] -- Warning: /home/hmf/VSCodeProjects/sploty/meta/test/src/icollection/IMapSpec.scala:882:19