Skip to content

export object.given does not respect priorities #15264

Closed
@erikerlandson

Description

@erikerlandson

Compiler version

3.1.2

Minimized code

object repro:
    // analogous to cats Eq, Hash, Order:
    class A[V]
    class B[V] extends A[V]
    class C[V] extends A[V]

    // resolve conflicts with prio trick
    object context extends prio1:
        given[V]: C[V] = new C[V]
    class prio1 extends prio2:
        given[V]: B[V] = new B[V]
    class prio2:
        given[V]: A[V] = new A[V]

    object exports:
        // this will erase prios and fail
        export context.given

Output

If you just import context.given the prio trick works:

Welcome to Scala 3.1.2 (11.0.15, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> import coulomb.cats.repro.*, coulomb.cats.repro.context.given
                                                                                                                                                                                                                
scala> summon[C[Int]]
val res0: coulomb.cats.repro.C[Int] = coulomb.cats.repro$C@25327ca9
                                                                                                                                                                                                                
scala> summon[B[Int]]
val res1: coulomb.cats.repro.B[Int] = coulomb.cats.repro$B@19257f00
                                                                                                                                                                                                                
scala> summon[A[Int]]
val res2: coulomb.cats.repro.C[Int] = coulomb.cats.repro$C@4441199e

BUT if you try to import exports.given the priority info is lost:

scala> import coulomb.cats.repro.exports.given
                                                                                                                                                                                                                
scala> summon[A[Int]]
-- Error: ----------------------------------------------------------------------
1 |summon[A[Int]]
  |              ^
  |ambiguous implicit arguments: both given instance given_C_V in object exports and given instance given_B_V in object exports match type coulomb.cats.repro.A[Int] of parameter x of method summon in object Predef
1 error found

Expectation

Ideally, the priority information would be preserved when importing via exports.given,
so the given definitions could be composed using scala 3's new export feature.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions