Skip to content

Commit 91d1122

Browse files
authored
Merge pull request #14654 from dwijnand/zipConserve
Tweak zipWithConserve to eliminate 3 casts
2 parents 895598f + 1bccaff commit 91d1122

File tree

6 files changed

+7
-12
lines changed

6 files changed

+7
-12
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ object Decorators {
144144
* `xs` to themselves. Also, it is required that `ys` is at least
145145
* as long as `xs`.
146146
*/
147-
def zipWithConserve[U](ys: List[U])(f: (T, U) => T): List[T] =
147+
def zipWithConserve[U, V <: T](ys: List[U])(f: (T, U) => V): List[V] =
148148
if (xs.isEmpty || ys.isEmpty) Nil
149149
else {
150150
val x1 = f(xs.head, ys.head)
151151
val xs1 = xs.tail.zipWithConserve(ys.tail)(f)
152-
if ((x1.asInstanceOf[AnyRef] eq xs.head.asInstanceOf[AnyRef]) &&
153-
(xs1 eq xs.tail)) xs
152+
if (x1.asInstanceOf[AnyRef] eq xs.head.asInstanceOf[AnyRef]) && (xs1 eq xs.tail)
153+
then xs.asInstanceOf[List[V]]
154154
else x1 :: xs1
155155
}
156156

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ case class Signature(paramsSig: List[ParamSig], resSig: TypeName) {
7171
else if (!this.paramsSig.hasSameLengthAs(that.paramsSig)) that
7272
else {
7373
val mapped = Signature(
74-
// DOTTY: we shouldn't have to explicitly pass a type argument to `update`,
75-
// see https://github.com/lampepfl/dotty/issues/4867
76-
this.paramsSig.zipWithConserve(that.paramsSig)(update[ParamSig]),
74+
this.paramsSig.zipWithConserve(that.paramsSig)(update),
7775
update(this.resSig, that.resSig))
7876
if (mapped == this) this else mapped
7977
}

compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ class TastyUnpickler(reader: TastyReader) {
5454
val end = start + length
5555
def readSignedRest(original: TermName, target: TermName): TermName =
5656
val result = readName().toTypeName
57-
// DOTTY: we shouldn't have to give an explicit type to paramsSig,
58-
// see https://github.com/lampepfl/dotty/issues/4867
59-
val paramsSig: List[Signature.ParamSig] = until(end)(readParamSig())
57+
val paramsSig = until(end)(readParamSig())
6058
val sig = Signature(paramsSig, result)
6159
SignedName(original, sig, target)
6260

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

-1
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,6 @@ object Erasure {
825825

826826
val args0 = outers ::: ownArgs
827827
val args1 = args0.zipWithConserve(xmt.paramInfos)(typedExpr)
828-
.asInstanceOf[List[Tree]]
829828

830829
def mkApply(finalFun: Tree, finalArgs: List[Tree]) =
831830
val app = untpd.cpy.Apply(tree)(finalFun, finalArgs)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class ReTyper(nestingLevel: Int = 0) extends Typer(nestingLevel) with ReChecking
110110

111111
override def handleUnexpectedFunType(tree: untpd.Apply, fun: Tree)(using Context): Tree = fun.tpe match {
112112
case mt: MethodType =>
113-
val args: List[Tree] = tree.args.zipWithConserve(mt.paramInfos)(typedExpr(_, _)).asInstanceOf[List[Tree]]
113+
val args: List[Tree] = tree.args.zipWithConserve(mt.paramInfos)(typedExpr)
114114
assignType(untpd.cpy.Apply(tree)(fun, args), fun, args)
115115
case _ =>
116116
super.handleUnexpectedFunType(tree, fun)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1969,7 +1969,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
19691969
}
19701970
else desugaredArg.withType(UnspecifiedErrorType)
19711971
}
1972-
args.zipWithConserve(tparams)(typedArg(_, _)).asInstanceOf[List[Tree]]
1972+
args.zipWithConserve(tparams)(typedArg)
19731973
}
19741974
val paramBounds = tparams.lazyZip(args).map {
19751975
case (tparam, untpd.WildcardTypeBoundsTree()) =>

0 commit comments

Comments
 (0)