Skip to content

Commit

Permalink
Test for #13001
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Jul 29, 2021
1 parent d1cdd6e commit a7d7fb7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/pos/i13001/Main_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
case class Foo(a: String)

trait Arbitrary[T]
trait Gen[+T]

object ArbitraryDerivation:
given deriveArb[A](using gen: DerivedGen[A]): Arbitrary[A] = ???

opaque type DerivedGen[A] = Gen[A]
object DerivedGen extends DerivedGenInstances

sealed abstract class DerivedGenInstances:
inline given derived[A](using gen: K0.Generic[A]): DerivedGen[A] =
val dummy: DerivedGen[A] = ???
gen.derive(dummy, dummy)

// from shapeless3-deriving
import scala.deriving.*
object K0 {
type Kind[C, O] = C { type Kind = K0.type ; type MirroredType = O ; type MirroredElemTypes <: Tuple }
type Generic[O] = Kind[Mirror, O]
type ProductGeneric[O] = Kind[Mirror.Product, O]
type CoproductGeneric[O] = Kind[Mirror.Sum, O]

extension [F[_], T](gen: Generic[T])
inline def derive(f: => (ProductGeneric[T] & gen.type) ?=> F[T], g: => (CoproductGeneric[T] & gen.type) ?=> F[T]): F[T] =
inline gen match {
case p: ProductGeneric[T] => f(using p.asInstanceOf)
case c: CoproductGeneric[T] => g(using c.asInstanceOf)
}
}
4 changes: 4 additions & 0 deletions tests/pos/i13001/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Test:
import ArbitraryDerivation.given
private def test[A: Arbitrary]: Unit = {}
test[Foo]

0 comments on commit a7d7fb7

Please sign in to comment.