Skip to content

Commit 33ac715

Browse files
oderskytanishiking
authored andcommitted
Test for scala#13001
1 parent 46d1324 commit 33ac715

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

tests/pos/i13001/Main_1.scala

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
case class Foo(a: String)
2+
3+
trait Arbitrary[T]
4+
trait Gen[+T]
5+
6+
object ArbitraryDerivation:
7+
given deriveArb[A](using gen: DerivedGen[A]): Arbitrary[A] = ???
8+
9+
opaque type DerivedGen[A] = Gen[A]
10+
object DerivedGen extends DerivedGenInstances
11+
12+
sealed abstract class DerivedGenInstances:
13+
inline given derived[A](using gen: K0.Generic[A]): DerivedGen[A] =
14+
val dummy: DerivedGen[A] = ???
15+
gen.derive(dummy, dummy)
16+
17+
// from shapeless3-deriving
18+
import scala.deriving.*
19+
object K0 {
20+
type Kind[C, O] = C { type Kind = K0.type ; type MirroredType = O ; type MirroredElemTypes <: Tuple }
21+
type Generic[O] = Kind[Mirror, O]
22+
type ProductGeneric[O] = Kind[Mirror.Product, O]
23+
type CoproductGeneric[O] = Kind[Mirror.Sum, O]
24+
25+
extension [F[_], T](gen: Generic[T])
26+
inline def derive(f: => (ProductGeneric[T] & gen.type) ?=> F[T], g: => (CoproductGeneric[T] & gen.type) ?=> F[T]): F[T] =
27+
inline gen match {
28+
case p: ProductGeneric[T] => f(using p.asInstanceOf)
29+
case c: CoproductGeneric[T] => g(using c.asInstanceOf)
30+
}
31+
}

tests/pos/i13001/Test_2.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Test:
2+
import ArbitraryDerivation.given
3+
private def test[A: Arbitrary]: Unit = {}
4+
test[Foo]

0 commit comments

Comments
 (0)