Skip to content

Commit 93d3d66

Browse files
authored
Merge pull request scala#130 from MasseGuillaume/apply-to
Extend the .to(CC) refactor to f(cc.to)
2 parents fe48078 + 304d918 commit 93d3d66

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

scalafix/input/src/main/scala/fix/ReplaceToSrc.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ object ReplaceToSrc {
1414

1515
def m2(xs: List[Int]): Iterable[Int] =
1616
xs.to
17+
18+
def f(xs: List[Int]): Unit = ()
19+
f(Set(1).to)
1720
}

scalafix/output/src/main/scala/fix/ReplaceToSrc.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ object ReplaceToSrc {
1515

1616
def m2(xs: List[Int]): Iterable[Int] =
1717
xs.to(scala.collection.immutable.IndexedSeq)
18+
19+
def f(xs: List[Int]): Unit = ()
20+
f(Set(1).to(scala.collection.immutable.List))
1821
}

scalafix/rules/src/main/scala/fix/Stable212Base.scala

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -273,22 +273,16 @@ trait Stable212Base extends CrossCompatibility { self: SemanticRule =>
273273
}.asPatch
274274

275275
case t @ Term.Select(_, to @ toTpe(n: Name)) if !handledTo.contains(n) =>
276-
// we only want f.to, not f.to(X)
277-
val applied =
278-
t.parent match {
279-
case Some(_:Term.Apply) => true
280-
case _ => false
276+
val synth = ctx.index.synthetics.find(_.position.end == to.pos.end)
277+
synth.map{ s =>
278+
s.text.parse[Term].get match {
279+
// we only want f.to, not f.to(X)
280+
case Term.Apply(_, List(toCol)) =>
281+
val col = extractCollection(toCol)
282+
ctx.addRight(to, "(" + col + ")")
283+
case _ => Patch.empty
281284
}
282-
283-
if (!applied) {
284-
val synth = ctx.index.synthetics.find(_.position.end == to.pos.end)
285-
synth.map{ s =>
286-
val res = s.text.parse[Term].get
287-
val Term.Apply(_, List(toCol)) = res
288-
val col = extractCollection(toCol)
289-
ctx.addRight(to, "(" + col + ")")
290-
}.getOrElse(Patch.empty)
291-
} else Patch.empty
285+
}.getOrElse(Patch.empty)
292286

293287
}.asPatch
294288

0 commit comments

Comments
 (0)