Skip to content

Commit 72883e9

Browse files
oderskynicolasstucki
authored andcommitted
Add tupleOf utility method
1 parent 22c1e0e commit 72883e9

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,4 +567,9 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
567567

568568
object TypeOps {
569569
@sharable var track: Boolean = false // !!!DEBUG
570+
571+
// TODO: Move other typeops here. It's a bit weird that they are a part of `ctx`
572+
573+
def tupleOf(ts: List[Type])(implicit ctx: Context): Type =
574+
(ts :\ (defn.UnitType: Type))(defn.PairType.appliedTo(_, _))
570575
}

compiler/src/dotty/tools/dotc/transform/TypeUtils.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ object TypeUtils {
4848
else throw new AssertionError("not a tuple")
4949
}
5050

51-
/** The `*:` equivalent of an instantce of a Tuple class */
51+
/** The `*:` equivalent of an instance of a Tuple class */
5252
def toNestedPairs(implicit ctx: Context): Type =
53-
(tupleElementTypes :\ (defn.UnitType: Type))(defn.PairType.appliedTo(_, _))
53+
TypeOps.tupleOf(tupleElementTypes)
5454
}
5555
}

compiler/src/dotty/tools/dotc/typer/Deriving.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ trait Deriving { this: Typer =>
7878
case _ =>
7979
(sym.termRef, Nil)
8080
}
81-
val elemShape = (elems :\ (defn.UnitType: Type))(defn.PairType.appliedTo(_, _))
81+
val elemShape = TypeOps.tupleOf(elems)
8282
defn.ShapeCaseType.appliedTo(constr, elemShape)
8383
}
8484

8585
/** The shape of `cls` if `cls` is sealed */
8686
private def sealedShape: Type = {
8787
val cases = children.map(caseShape).filter(_.exists)
88-
val casesShape = (cases :\ (defn.UnitType: Type))(defn.PairType.appliedTo(_, _))
88+
val casesShape = TypeOps.tupleOf(cases)
8989
defn.ShapeCasesType.appliedTo(casesShape)
9090
}
9191

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1919,7 +1919,7 @@ class Typer extends Namer
19191919
else {
19201920
val elemTpes = (elems, pts).zipped.map((elem, pt) =>
19211921
ctx.typeComparer.widenInferred(elem.tpe, pt))
1922-
val resTpe = (elemTpes :\ (defn.UnitType: Type))(defn.PairType.appliedTo(_, _))
1922+
val resTpe = TypeOps.tupleOf(elemTpes)
19231923
app1.cast(resTpe)
19241924
}
19251925
}

0 commit comments

Comments
 (0)