-
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.
Merge pull request #6879 from milessabin/topic/mirror-implicit-scope
Support implicit scope augmentation for Mirror
- Loading branch information
Showing
3 changed files
with
131 additions
and
75 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,15 @@ | ||
import scala.deriving._ | ||
|
||
object Test { | ||
class SomeClass | ||
case class ISB(i: Int, s: String, b: Boolean) | ||
case class BI(b: Boolean, i: Int) | ||
|
||
val v0 = the[Mirror.ProductOf[ISB]] // OK | ||
val v1 = the[SomeClass & Mirror.ProductOf[ISB]] // error | ||
val v2 = the[Mirror.ProductOf[ISB] & Mirror.ProductOf[BI]] // error | ||
val v3 = the[Mirror.Product { type MirroredType = ISB ; def foo: Int }] // error | ||
val v4 = the[Mirror.Product { type MirroredType = ISB ; def foo(i: Int): Int }] // error | ||
val v5 = the[Mirror.Product { type MirroredType = ISB ; def foo[T](t: T): T }] // error // error | ||
val v6 = the[Mirror.Product { type MirroredType = ISB ; val foo: Int }] // error | ||
} |
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 | ||
} |