-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mirrors can now be materialized with additional type member refinements.
Any additional type members will contribute to the implicit scope of any searches involving the type of the summoned Mirror. Typically such types will be the singleton types of objects containing implicit extension methods for the Mirror, or other related implicit definitions. Pass through all extra refinements
- Loading branch information
1 parent
a35d724
commit a2ed239
Showing
2 changed files
with
59 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import scala.deriving._ | ||
|
||
object Test { | ||
object K0 { | ||
type Generic[T] = Mirror { type Scope = K0.type ; type MirroredType = T ; type MirroredElemTypes } | ||
given Ops { | ||
inline def (gen: Generic[T]) toRepr[T <: Product](t: T): gen.MirroredElemTypes = Tuple.fromProduct(t).asInstanceOf | ||
} | ||
} | ||
|
||
object K1 { | ||
type Generic[F[_]] = Mirror { type Scope = K1.type ; type MirroredType = F ; type MirroredElemTypes[_] } | ||
given Ops { | ||
inline def (gen: Generic[F]) toRepr[F[_] <: Product, T](t: F[T]): gen.MirroredElemTypes[T] = Tuple.fromProduct(t).asInstanceOf | ||
} | ||
} | ||
|
||
case class ISB(i: Int, s: String, b: Boolean) | ||
val v0 = the[K0.Generic[ISB]] | ||
val v1 = v0.toRepr(ISB(23, "foo", true)) | ||
val v2: (Int, String, Boolean) = v1 | ||
|
||
case class Box[T](t: T) | ||
val v3 = the[K1.Generic[Box]] | ||
val v4 = v3.toRepr(Box(23)) | ||
val v5: Tuple1[Int] = v4 | ||
} |