-
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.
Refine constraining scheme for result types
- Take MatchTypes into account - Add test cases for tests that failed originally and would otherwise fail again after this PR. i19415.scala is fixed by the MatchType extension. i19749.scala was fixed by adding a `transparent`.
- Loading branch information
Showing
3 changed files
with
88 additions
and
2 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,24 @@ | ||
def Test = { | ||
val left: Parser[String] = ??? | ||
val right: Parser[Int] = ??? | ||
val both = left && right | ||
|
||
val works = both.map(Ior.Both.apply) | ||
val fails = (left && right).map(Ior.Both.apply) | ||
} | ||
|
||
trait Parser[T]: | ||
final def &&[T2](other: Parser[T2])(implicit zip: Zip[T, T2]): Parser[zip.Out] = ??? | ||
final def map[T2](f: T => T2): Parser[T2] = ??? | ||
|
||
infix trait Ior[+A, +B] | ||
object Ior: | ||
final case class Both[+A, +B](a: A, b: B) extends (A Ior B) | ||
|
||
trait Zip[In1, In2]: | ||
type Out | ||
|
||
object Zip { | ||
type Out[In1, In2, O] = Zip[In1, In2] { type Out = O } | ||
implicit def zip2[_1, _2]: Zip.Out[_1, _2, (_1, _2)] = ??? | ||
} |
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,54 @@ | ||
case class Person(id: Int) | ||
|
||
class GeodeContinuousSourceSpec { | ||
summon[PdxEncoder[Person]] | ||
} | ||
|
||
trait PdxEncoder[A] { | ||
def encode(a: A): Boolean | ||
} | ||
|
||
object PdxEncoder extends ObjectEncoder { | ||
implicit def intEncoder: PdxEncoder[Int] = ??? | ||
} | ||
|
||
trait ObjectEncoder { | ||
given emptyTupleEncoder: PdxEncoder[EmptyTuple] = ??? | ||
|
||
given tupleEncoder[K <: String, H, T <: Tuple](using | ||
m: ValueOf[K], | ||
hEncoder: PdxEncoder[H], | ||
tEncoder: PdxEncoder[T] | ||
): PdxEncoder[FieldType[K, H] *: T] = ??? | ||
|
||
given objectEncoder[A, Repr <: Tuple](using | ||
gen: LabelledGeneric.Aux[A, Repr], | ||
tupleEncoder: PdxEncoder[Repr] | ||
): PdxEncoder[A] = ??? | ||
} | ||
|
||
import scala.deriving.Mirror | ||
|
||
private type FieldType[K, +V] = V & KeyTag[K, V] | ||
private type KeyTag[K, +V] | ||
private type ZipWith[T1 <: Tuple, T2 <: Tuple, F[_, _]] <: Tuple = (T1, T2) match { | ||
case (h1 *: t1, h2 *: t2) => F[h1, h2] *: ZipWith[t1, t2, F] | ||
case (EmptyTuple, ?) => EmptyTuple | ||
case (?, EmptyTuple) => EmptyTuple | ||
case _ => Tuple | ||
} | ||
|
||
private trait LabelledGeneric[A] { | ||
type Repr | ||
} | ||
|
||
private object LabelledGeneric { | ||
type Aux[A, R] = LabelledGeneric[A] { type Repr = R } | ||
|
||
transparent inline given productInst[A <: Product](using | ||
m: Mirror.ProductOf[A] | ||
): LabelledGeneric.Aux[A, ZipWith[m.MirroredElemLabels, m.MirroredElemTypes, FieldType]] = | ||
new LabelledGeneric[A] { | ||
type Repr = Tuple & ZipWith[m.MirroredElemLabels, m.MirroredElemTypes, FieldType] | ||
} | ||
} |