Skip to content

Implicit conversion with abstract HKT not firing #12216

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

Closed
japgolly opened this issue Apr 26, 2021 · 0 comments · Fixed by #14797
Closed

Implicit conversion with abstract HKT not firing #12216

japgolly opened this issue Apr 26, 2021 · 0 comments · Fixed by #14797

Comments

@japgolly
Copy link
Contributor

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
pweisenburger referenced this issue in pweisenburger/scala3 Mar 27, 2022
Closes lampepfl#3058
Closes lampepfl#10943
Closes lampepfl#12216
Closes lampepfl#12655
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant