scalatypeclassscala-3opaque-types

Using `opaque type` as a typeclass in Scala


Any idea why this does not compile: https://scastie.scala-lang.org/iPmLyim4Q8aQ2aMNIfj2gA

opaque type Global[Value] = Unit
object Global:
  def derived[Value]: Global[Value] = ()

case class Yo() derives Global

❗Playground.Global is not a class type

But this does: https://scastie.scala-lang.org/d148ISEcQ8Swu96lH6JMCw

case class Global[Value]()
object Global:
  def derived[Value]: Global[Value] = Global()

case class Yo() derives Global

?


Solution

  • As @MartinHH mentioned in the comments, this is not supported as of today and an enhancement ticket is open.

    Thanks