I don’t think that class Boxed
has to be an implicit class for it to work.
With a little hack I can make the opaque type work. But perhaps that partly defeats the purpose of an opaque type… And I’m not sure that it will make much difference in the bytecode.
Welcome to Scala 3.3.1 (21.0.2, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> object Test:
| opaque type Box[A] <: Dynamic = A & Dynamic
| extension [A](box: Box[A])
| inline def selectDynamic(name: String): String = "calling " + name
|
| extension [A](a: A)
| inline def ! : Box[A] = a.asInstanceOf[A & Dynamic]
|
// defined object Test
scala> import Test.*
scala> Option(3).!.foo
val res0: String = calling foo