Skip to content

Commit 40ee013

Browse files
committed
fix some deprecations
1 parent f8f8a18 commit 40ee013

File tree

11 files changed

+34
-30
lines changed

11 files changed

+34
-30
lines changed

compiler/src/dotty/tools/dotc/Bench.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object Bench extends Driver {
1515
@sharable private[this] var numRuns = 1
1616

1717
private def ntimes(n: Int)(op: => Reporter): Reporter =
18-
(emptyReporter /: (0 until n)) ((_, _) => op)
18+
(0 until n).foldLeft(emptyReporter)((_, _) => op)
1919

2020
override def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter =
2121
ntimes(numRuns) {

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
5656
ctx.initialize()(start) // re-initialize the base context with start
5757
def addImport(ctx: Context, refFn: () => TermRef) =
5858
ctx.fresh.setImportInfo(ImportInfo.rootImport(refFn)(ctx))
59-
(start.setRun(this) /: defn.RootImportFns)(addImport)
59+
defn.RootImportFns.foldLeft(start.setRun(this))(addImport)
6060
}
6161

6262
private[this] var compiling = false

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,12 @@ object desugar {
491491
// Annotations are dropped from the constructor parameters but should be
492492
// preserved in all derived parameters.
493493
val derivedTparams = {
494-
val impliedTparamsIt = impliedTparams.toIterator
494+
val impliedTparamsIt = impliedTparams.iterator
495495
constrTparams.map(tparam => derivedTypeParam(tparam)
496496
.withAnnotations(impliedTparamsIt.next().mods.annotations))
497497
}
498498
val derivedVparamss = {
499-
val constrVparamsIt = constrVparamss.toIterator.flatten
499+
val constrVparamsIt = constrVparamss.iterator.flatten
500500
constrVparamss.nestedMap(vparam => derivedTermParam(vparam)
501501
.withAnnotations(constrVparamsIt.next().mods.annotations))
502502
}
@@ -560,7 +560,7 @@ object desugar {
560560
case _ =>
561561
constrVparamss
562562
}
563-
val nu = (makeNew(classTypeRef) /: vparamss) { (nu, vparams) =>
563+
val nu = vparamss.foldLeft(makeNew(classTypeRef)) { (nu, vparams) =>
564564
val app = Apply(nu, vparams.map(refOfDef))
565565
vparams match {
566566
case vparam :: _ if vparam.mods.is(Given) => app.setGivenApply()
@@ -700,10 +700,9 @@ object desugar {
700700
isEnumCase) anyRef
701701
else
702702
// todo: also use anyRef if constructor has a dependent method type (or rule that out)!
703-
(constrVparamss :\ classTypeRef) (
704-
(vparams, restpe) => Function(vparams map (_.tpt), restpe))
703+
constrVparamss.foldRight(classTypeRef)((vparams, restpe) => Function(vparams map (_.tpt), restpe))
705704
def widenedCreatorExpr =
706-
(creatorExpr /: widenDefs)((rhs, meth) => Apply(Ident(meth.name), rhs :: Nil))
705+
widenDefs.foldLeft(creatorExpr)((rhs, meth) => Apply(Ident(meth.name), rhs :: Nil))
707706
val applyMeths =
708707
if (mods.is(Abstract)) Nil
709708
else {
@@ -790,12 +789,12 @@ object desugar {
790789

791790
val cdef1 = addEnumFlags {
792791
val tparamAccessors = {
793-
val impliedTparamsIt = impliedTparams.toIterator
792+
val impliedTparamsIt = impliedTparams.iterator
794793
derivedTparams.map(_.withMods(impliedTparamsIt.next().mods))
795794
}
796795
val caseAccessor = if (isCaseClass) CaseAccessor else EmptyFlags
797796
val vparamAccessors = {
798-
val originalVparamsIt = originalVparamss.toIterator.flatten
797+
val originalVparamsIt = originalVparamss.iterator.flatten
799798
derivedVparamss match {
800799
case first :: rest =>
801800
first.map(_.withMods(originalVparamsIt.next().mods | caseAccessor)) ++
@@ -1279,7 +1278,7 @@ object desugar {
12791278
val ttree = ctx.typerPhase match {
12801279
case phase: FrontEnd if phase.stillToBeEntered(parts.last) =>
12811280
val prefix =
1282-
((Ident(nme.ROOTPKG): Tree) /: parts.init)((qual, name) =>
1281+
parts.init.foldLeft((Ident(nme.ROOTPKG): Tree))((qual, name) =>
12831282
Select(qual, name.toTermName))
12841283
Select(prefix, parts.last.toTypeName)
12851284
case _ =>

compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ object DesugarEnums {
177177
parentTypes.head match {
178178
case parent: RefTree if parent.name == enumClass.name =>
179179
// need a widen method to compute correct type parameters for enum base class
180-
val widenParamType = (appliedEnumRef /: parentTypes.tail)(makeAndType)
180+
val widenParamType = parentTypes.tail.foldLeft(appliedEnumRef)(makeAndType)
181181
val widenParam = makeSyntheticParameter(tpt = widenParamType)
182182
val widenDef = DefDef(
183183
name = s"${cdef.name}$$to$$${enumClass.name}".toTermName,

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
270270
* trait or class with this body can have as flags.
271271
*/
272272
def bodyKind(body: List[Tree])(implicit ctx: Context): FlagSet =
273-
(NoInitsInterface /: body)((fs, stat) => fs & defKind(stat))
273+
body.foldLeft(NoInitsInterface)((fs, stat) => fs & defKind(stat))
274274

275275
/** Checks whether predicate `p` is true for all result parts of this expression,
276276
* where we zoom into Ifs, Matches, and Blocks.
@@ -414,7 +414,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
414414
Impure
415415
}
416416

417-
private def minOf(l0: PurityLevel, ls: List[PurityLevel]) = (l0 /: ls)(_ `min` _)
417+
private def minOf(l0: PurityLevel, ls: List[PurityLevel]) = ls.foldLeft(l0)(_ `min` _)
418418

419419
def isPurePath(tree: Tree)(implicit ctx: Context): Boolean = tree.tpe match {
420420
case tpe: ConstantType => exprPurity(tree) >= Pure
@@ -825,8 +825,8 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
825825
case t1: Ident => t1.symbol.hashCode
826826
case t1 @ Select(q1, _) => t1.symbol.hashCode * 41 + q1.hash
827827
case Literal(c1) => c1.hashCode
828-
case Apply(f1, as1) => (f1.hash /: as1)((h, arg) => h * 41 + arg.hash)
829-
case TypeApply(f1, ts1) => (f1.hash /: ts1)((h, arg) => h * 41 + arg.tpe.hash)
828+
case Apply(f1, as1) => as1.foldLeft(f1.hash)((h, arg) => h * 41 + arg.hash)
829+
case TypeApply(f1, ts1) => ts1.foldLeft(f1.hash)((h, arg) => h * 41 + arg.tpe.hash)
830830
case _ => t1.hashCode
831831
}
832832
}

compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,13 @@ class TreeTypeMap(
185185
def withMappedSyms(syms: List[Symbol], mapped: List[Symbol]): TreeTypeMap = {
186186
val symsChanged = syms ne mapped
187187
val substMap = withSubstitution(syms, mapped)
188-
val fullMap = (substMap /: mapped.filter(_.isClass)) { (tmap, cls) =>
188+
val fullMap = mapped.filter(_.isClass).foldLeft(substMap) { (tmap, cls) =>
189189
val origDcls = cls.info.decls.toList
190190
val mappedDcls = ctx.mapSymbols(origDcls, tmap)
191191
val tmap1 = tmap.withMappedSyms(origDcls, mappedDcls)
192-
if (symsChanged) (origDcls, mappedDcls).zipped.foreach(cls.asClass.replace)
192+
if (symsChanged) {
193+
(origDcls, mappedDcls).zipped.foreach(cls.asClass.replace)
194+
}
193195
tmap1
194196
}
195197
if (symsChanged || (fullMap eq substMap)) fullMap

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ object Trees {
851851
override def isEmpty: Boolean = trees.isEmpty
852852
override def toList: List[Tree[T]] = flatten(trees)
853853
override def toString: String = if (isEmpty) "EmptyTree" else "Thicket(" + trees.mkString(", ") + ")"
854-
override def span: Span = (NoSpan /: trees) ((span, t) => span union t.span)
854+
override def span: Span = trees.foldLeft(NoSpan) ((span, t) => span union t.span)
855855

856856
override def withSpan(span: Span): this.type =
857857
mapElems(_.withSpan(span)).asInstanceOf[this.type]
@@ -1364,7 +1364,7 @@ object Trees {
13641364
// Ties the knot of the traversal: call `foldOver(x, tree))` to dive in the `tree` node.
13651365
def apply(x: X, tree: Tree)(implicit ctx: Context): X
13661366

1367-
def apply(x: X, trees: Traversable[Tree])(implicit ctx: Context): X = (x /: trees)(apply)
1367+
def apply(x: X, trees: Traversable[Tree])(implicit ctx: Context): X = trees.foldLeft(x)(apply)
13681368
def foldOver(x: X, tree: Tree)(implicit ctx: Context): X =
13691369
if (tree.source != ctx.source && tree.source.exists)
13701370
foldOver(x, tree)(ctx.withSource(tree.source))
@@ -1445,7 +1445,7 @@ object Trees {
14451445
this(this(x, tpt), tree.rhs)
14461446
case tree @ DefDef(name, tparams, vparamss, tpt, _) =>
14471447
implicit val ctx = localCtx
1448-
this(this((this(x, tparams) /: vparamss)(apply), tpt), tree.rhs)
1448+
this(this(vparamss.foldLeft(this(x, tparams))(apply), tpt), tree.rhs)
14491449
case TypeDef(name, rhs) =>
14501450
implicit val ctx = localCtx
14511451
this(x, rhs)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ trait NamerContextOps { this: Context =>
133133
/** The method type corresponding to given parameters and result type */
134134
def methodType(typeParams: List[Symbol], valueParamss: List[List[Symbol]], resultType: Type, isJava: Boolean = false)(implicit ctx: Context): Type = {
135135
val monotpe =
136-
(valueParamss :\ resultType) { (params, resultType) =>
136+
valueParamss.foldRight(resultType) { (params, resultType) =>
137137
val (isContextual, isImplicit, isErased) =
138138
if (params.isEmpty) (false, false, false)
139139
else (params.head.is(Given), params.head.is(Implicit), params.head.is(Erased))
@@ -720,7 +720,7 @@ class Namer { typer: Typer =>
720720

721721
stats.foreach(expand)
722722
mergeCompanionDefs()
723-
val ctxWithStats = (ctx /: stats) ((ctx, stat) => indexExpanded(stat)(ctx))
723+
val ctxWithStats = stats.foldLeft(ctx)((ctx, stat) => indexExpanded(stat)(ctx))
724724
createCompanionLinks(ctxWithStats)
725725
ctxWithStats
726726
}
@@ -1248,7 +1248,7 @@ class Namer { typer: Typer =>
12481248
// TODO: Look only at member of supertype instead?
12491249
lazy val schema = paramFn(WildcardType)
12501250
val site = sym.owner.thisType
1251-
((NoType: Type) /: sym.owner.info.baseClasses.tail) { (tp, cls) =>
1251+
sym.owner.info.baseClasses.tail.foldLeft(NoType: Type) { (tp, cls) =>
12521252
def instantiatedResType(info: Type, tparams: List[Symbol], paramss: List[List[Symbol]]): Type = info match {
12531253
case info: PolyType =>
12541254
if (info.paramNames.length == typeParams.length)

library/src-bootstrapped/scala/tasty/reflect/TreeUtils.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ trait TreeUtils
1414
def foldTree(x: X, tree: Tree) given (ctx: Context): X
1515
def foldPattern(x: X, tree: Pattern) given (ctx: Context): X
1616

17-
def foldTrees(x: X, trees: Iterable[Tree]) given (ctx: Context): X = (x /: trees)(foldTree)
18-
def foldPatterns(x: X, trees: Iterable[Pattern]) given (ctx: Context): X = (x /: trees)(foldPattern)
17+
def foldTrees(x: X, trees: Iterable[Tree]) given (ctx: Context): X = trees.foldLeft(x)(foldTree)
18+
def foldPatterns(x: X, trees: Iterable[Pattern]) given (ctx: Context): X = trees.foldLeft(x)(foldPattern)
1919

2020
def foldOverTree(x: X, tree: Tree) given (ctx: Context): X = {
2121
def localCtx(definition: Definition): Context = definition.symbol.localContext
@@ -65,7 +65,7 @@ trait TreeUtils
6565
foldTrees(foldTree(x, tpt), rhs)
6666
case IsDefinition(ddef @ DefDef(_, tparams, vparamss, tpt, rhs)) =>
6767
implicit val ctx = localCtx(ddef)
68-
foldTrees(foldTree((foldTrees(x, tparams) /: vparamss)(foldTrees), tpt), rhs)
68+
foldTrees(foldTree(vparamss.foldLeft(foldTrees(x, tparams))(foldTrees), tpt), rhs)
6969
case IsDefinition(tdef @ TypeDef(_, rhs)) =>
7070
implicit val ctx = localCtx(tdef)
7171
foldTree(x, rhs)

library/src/scala/tasty/reflect/Printers.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,9 @@ trait Printers
13711371

13721372
}
13731373

1374+
inline private val qc = '\''
1375+
inline private val qSc = '"'
1376+
13741377
def printConstant(const: Constant): Buffer = const match {
13751378
case Constant(()) => this += highlightLiteral("()")
13761379
case Constant(null) => this += highlightLiteral("null")
@@ -1381,8 +1384,8 @@ trait Printers
13811384
case Constant(v: Long) => this += highlightLiteral(v.toString + "L")
13821385
case Constant(v: Float) => this += highlightLiteral(v.toString + "f")
13831386
case Constant(v: Double) => this += highlightLiteral(v.toString)
1384-
case Constant(v: Char) => this += highlightString('\'' + escapedChar(v) + '\'')
1385-
case Constant(v: String) => this += highlightString('"' + escapedString(v) + '"')
1387+
case Constant(v: Char) => this += highlightString(s"${qc}${escapedChar(v)}${qc}")
1388+
case Constant(v: String) => this += highlightString(s"${qSc}${escapedString(v)}${qSc}")
13861389
case Constant.ClassTag(v) =>
13871390
this += "classOf"
13881391
inSquare(printType(v))

library/src/scala/tasty/reflect/TreeOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ trait TreeOps extends Core {
196196
* `tree (argss(0)) ... (argss(argss.length -1))`
197197
*/
198198
def appliedToArgss(argss: List[List[Term]]) given (ctx: Context): Term =
199-
((self: Term) /: argss)(Apply(_, _))
199+
argss.foldLeft(self: Term)(Apply(_, _))
200200

201201
/** The current tree applied to (): `tree()` */
202202
def appliedToNone given (ctx: Context): Apply = appliedToArgs(Nil)

0 commit comments

Comments
 (0)