Skip to content

Implicit conversion with abstract HKT not firing #12216

Closed
@japgolly

Description

@japgolly

Compiler version

3.0.0-RC3

Minimized code

sealed abstract class CtorType[P]

object CtorType {
  final class Props[P] extends CtorType[P] {
    def whyHelloThere(props: P): Unit = ()
  }
}

trait Comp[P, CT[p] <: CtorType[p]] {
  val ctor: CT[P]
}
object Comp {
  implicit def autoCtor[P, CT[p] <: CtorType[p]](c: Comp[P, CT]): CT[P] = c.ctor
}

object Test {
  val comp: Comp[Int, CtorType.Props] = ???

  comp.whyHelloThere(3)                // error: should work
  Comp.autoCtor(comp).whyHelloThere(3) // works
}

Output

[error] 20 |  comp.whyHelloThere(3)                // error: should work
[error]    |  ^^^^^^^^^^^^^^^^^^
[error]    |  value whyHelloThere is not a member of Comp[Int, CtorType.Props]
[error] one error found

Expectation

It works in Scala 2.x, it should work here too.

Workaround

Duplicate the autoCtor for each subclass of CtorType, remove the CT type param, and hardcode the CT value.

  // implicit def autoCtor[P, CT[p] <: CtorType[p]](c: Comp[P, CT]): CT[P] = c.ctor
  implicit def autoCtorP[P](c: Comp[P, CtorType.Props]): CtorType.Props[P] = c.ctor

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions