|
| 1 | + |
| 2 | +trait Summon[R, T <: R]: |
| 3 | + type Out |
| 4 | +object Summon: |
| 5 | + given [R, T <: R]: Summon[R, T] with |
| 6 | + type Out = R |
| 7 | + |
| 8 | +sealed class Modifier[+A, +P] |
| 9 | +type ModifierAny = Modifier[Any, Any] |
| 10 | +sealed trait ISCONST[T <: Boolean] |
| 11 | +type CONST = ISCONST[true] |
| 12 | + |
| 13 | +trait DFTypeAny |
| 14 | +trait DFBits[W <: Int] extends DFTypeAny |
| 15 | +trait DFVal[+T <: DFTypeAny, +M <: ModifierAny] |
| 16 | +type DFValAny = DFVal[DFTypeAny, ModifierAny] |
| 17 | +type DFValTP[+T <: DFTypeAny, +P] = DFVal[T, Modifier[Any, P]] |
| 18 | +type DFConstOf[+T <: DFTypeAny] = DFVal[T, Modifier[Any, CONST]] |
| 19 | + |
| 20 | +trait Candidate[R]: |
| 21 | + type OutW <: Int |
| 22 | + type OutP |
| 23 | +object Candidate: |
| 24 | + given [W <: Int, P, R <: DFValTP[DFBits[W], P]]: Candidate[R] with |
| 25 | + type OutW = W |
| 26 | + type OutP = P |
| 27 | + |
| 28 | +extension [L <: DFValAny](lhs: L)(using icL: Candidate[L]) |
| 29 | + def ^^^[R](rhs: R)(using |
| 30 | + icR: Candidate[R] |
| 31 | + ): DFValTP[DFBits[icL.OutW], icL.OutP | icR.OutP] = ??? |
| 32 | + def ^^^ : Unit = ??? |
| 33 | +extension [L](lhs: L) |
| 34 | + def ^^^[RW <: Int, RP]( |
| 35 | + rhs: DFValTP[DFBits[RW], RP] |
| 36 | + )(using es: Summon[L, lhs.type])(using |
| 37 | + c: Candidate[L] |
| 38 | + )(using check: c.OutW =:= c.OutW): DFValTP[DFBits[c.OutW], c.OutP | RP] = ??? |
| 39 | + |
| 40 | +val x: DFConstOf[DFBits[8]] = ??? |
| 41 | +val zzz = x ^^^ x ^^^ x |
| 42 | + |
| 43 | + |
| 44 | +object Minimized: |
| 45 | + trait DFVal[+T <: Int, +P] |
| 46 | + |
| 47 | + trait Summon[R, T <: R] |
| 48 | + given [R, T <: R]: Summon[R, T] with {} |
| 49 | + |
| 50 | + trait Candidate[R]: |
| 51 | + type OutW <: Int |
| 52 | + type OutP |
| 53 | + given [W <: Int, P, R <: DFVal[W, P]]: Candidate[R] with |
| 54 | + type OutW = W |
| 55 | + type OutP = P |
| 56 | + |
| 57 | + extension [L <: DFVal[Int, Any]](lhs: L)(using icL: Candidate[L]) |
| 58 | + def ^^^[R](rhs: R) |
| 59 | + (using icR: Candidate[R]) |
| 60 | + : DFVal[icL.OutW, icL.OutP | icR.OutP] = ??? |
| 61 | + def ^^^ : Unit = ??? |
| 62 | + |
| 63 | + extension [L](lhs: L) |
| 64 | + def ^^^[RW <: Int, RP](rhs: DFVal[RW, RP]) |
| 65 | + (using es: Summon[L, lhs.type]) |
| 66 | + (using c: Candidate[L]) |
| 67 | + (using check: c.OutW =:= c.OutW) |
| 68 | + : DFVal[c.OutW, c.OutP | RP] = ??? |
| 69 | + |
| 70 | + val x: DFVal[8, true] = ??? |
| 71 | + val z1 = x ^^^ x // Ok |
| 72 | + val z2 = z1 ^^^ x // Ok |
| 73 | + val zzz = x ^^^ x ^^^ x // Error before changes |
| 74 | + |
| 75 | + /* Before the changes, when `def ^^^ : Unit = ???` is present, |
| 76 | + * all of z1, z2, zzz attempt to use the last `def ^^^`, |
| 77 | + * despite it being less specific than the 1st one. |
| 78 | + */ |
| 79 | +end Minimized |
0 commit comments