-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
It would nice that opaque type aliases were given evidence at typelevel. e.g.
def funThatExceptOpaqueTypeAlias[T: OpaqueAlias] = println("ok")
opaque type Foo = Double
funThatExceptOpaqueTypeAlias[Foo] // ok
funThatExceptOpaqueTypeAlias[Double] // do not compileSomething as below can be designed.
sealed trait OpaqueAlias[T] {}
object OpaqueAlias:
import scala.quoted.{ Expr, Quotes, Type }
inline given materialized[T]: OpaqueAlias[T] = ${ impl[T] }
private def impl[T: Type](using q: Quotes): Expr[OpaqueAlias[T]] = {
import q.reflect.*
TypeRepr.of[T] match {
case ref: TypeRef if ref.isOpaqueAlias =>
ref.asType match {
case tpe @ '[t] => '{ new OpaqueAlias[T] {} }
}
case tpr =>
report.errorAndAbort(s"${tpr.show} is not an opaque alias")
}
}
end OpaqueAliasMetadata
Metadata
Assignees
Labels
No labels