diff --git a/src/main/scala/scala/tools/refactoring/implementations/oimports/NotPackageImportParticipants.scala b/src/main/scala/scala/tools/refactoring/implementations/oimports/NotPackageImportParticipants.scala index 4d6d6afe..12f06616 100644 --- a/src/main/scala/scala/tools/refactoring/implementations/oimports/NotPackageImportParticipants.scala +++ b/src/main/scala/scala/tools/refactoring/implementations/oimports/NotPackageImportParticipants.scala @@ -190,7 +190,7 @@ class NotPackageImportParticipants[O <: OrganizeImports](val organizeImportsInst } (imp, usedSelectors) }.collect { - case (imp, selectors @ h :: _) => imp.copy(selectors = selectors).setPos(imp.pos) + case (imp, selectors @ h :: _) => imp.copy(selectors = selectors).setPos(imp.pos).setSymbol(imp.symbol).setType(imp.tpe) }.toList } @@ -201,9 +201,7 @@ class NotPackageImportParticipants[O <: OrganizeImports](val organizeImportsInst protected def doApply(trees: List[Import]) = trees.map { imp => val wild = imp.selectors.find(_.name == nme.WILDCARD) if (wild.nonEmpty) { - val newImp = imp.copy(selectors = imp.selectors.filter { renamed }.sortBy { _.name } ::: wild.toList).setPos(imp.pos) - newImp.symbol = imp.symbol - newImp + imp.copy(selectors = imp.selectors.filter { renamed }.sortBy { _.name } ::: wild.toList).setPos(imp.pos).setSymbol(imp.symbol).setType(imp.tpe) } else imp }.groupBy { diff --git a/src/test/scala/scala/tools/refactoring/tests/implementations/imports/OrganizeImportsTest.scala b/src/test/scala/scala/tools/refactoring/tests/implementations/imports/OrganizeImportsTest.scala index f3383ddf..b2660e24 100644 --- a/src/test/scala/scala/tools/refactoring/tests/implementations/imports/OrganizeImportsTest.scala +++ b/src/test/scala/scala/tools/refactoring/tests/implementations/imports/OrganizeImportsTest.scala @@ -5309,4 +5309,37 @@ class OrganizeImportsTest extends OrganizeImportsBaseTest { } """ isNotModified } applyRefactoring organizeCustomized(dependencies = Dependencies.RecomputeAndModify) + + @Test + def shouldNotRemoveImportWhenPathIsPartiallyGiven_v1() = new FileSet { + """ + /*<-*/ + package acme + + object Main extends App { + import scala.concurrent.duration + import scala.concurrent.duration.FiniteDuration + + val d1: FiniteDuration = ??? + val d2: duration.FiniteDuration = ??? + } + """ isNotModified + } applyRefactoring organizeCustomized(dependencies = Dependencies.RecomputeAndModify) + + @Ignore("FIXME") + @Test + def shouldNotRemoveImportWhenPathIsPartiallyGiven_v2() = new FileSet { + """ + /*<-*/ + package acme + + import scala.concurrent.duration + import scala.concurrent.duration.FiniteDuration + + object Main extends App { + val d1: FiniteDuration = ??? + val d2: duration.FiniteDuration = ??? + } + """ isNotModified + } applyRefactoring organizeCustomized(dependencies = Dependencies.RecomputeAndModify) }