Skip to content
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

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

Open
hmf opened this issue Apr 20, 2024 · 0 comments
Open

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

hmf opened this issue Apr 20, 2024 · 0 comments

Comments

@hmf
Copy link

hmf commented Apr 20, 2024

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 
@hmf hmf changed the title When using singleton types assertEquals does not work but `== does When using singleton types assertEquals does not work but == does Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant