Skip to content

Commit fce1608

Browse files
committed
Workaround for scalacenter/scalafix#478
This commit can be reverted once the issue is closed
1 parent 66c9265 commit fce1608

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

rules/src/main/scala/fix/Collectionstrawman_v0.scala

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,28 @@ case class Collectionstrawman_v0(index: SemanticdbIndex)
2929
)
3030

3131
def replaceExtensionMethods(ctx: RuleCtx): Patch = {
32+
val visited = collection.mutable.Set.empty[String]
3233
val toImport = for {
3334
r <- ctx.index.names
3435
in = r.symbol.normalized
3536
out <- unimports.get(in).toList
37+
if !visited(out.name)
3638
} yield {
39+
visited += out.name
3740
val name = in.name
38-
val names = name :: additionalUnimports.get(name)
39-
.fold(List.empty[String])(_ :: Nil)
40-
ctx.addGlobalImport(out) +
41-
ctx.addGlobalImport(
42-
Importer(q"scala.Predef", names.map(n => Importee.Unimport(Name(n)))))
41+
def visiting(s: String): List[String] =
42+
if (!visited(s)) {
43+
visited += s
44+
s :: Nil
45+
} else Nil
46+
val names = visiting(name) ::: additionalUnimports.get(name)
47+
.fold(List.empty[String])(visiting)
48+
if (names.isEmpty) ctx.addGlobalImport(out)
49+
else {
50+
ctx.addGlobalImport(out) +
51+
ctx.addGlobalImport(
52+
Importer(q"scala.Predef", names.map(n => Importee.Unimport(Name(n)))))
53+
}
4354
}
4455
val predefUnderscore =
4556
if (toImport.isEmpty) Patch.empty

0 commit comments

Comments
 (0)