Skip to content

Commit 72894aa

Browse files
committed
If there is an import selection for an indent, attach the original name
1 parent 79500f7 commit 72894aa

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ class CheckUnused private (phaseMode: CheckUnused.PhaseMode, suffix: String, _ke
9696
ctx
9797

9898
override def prepareForSelect(tree: tpd.Select)(using Context): Context =
99-
unusedDataApply(_.registerUsed(tree.symbol, Some(tree.name)))
99+
val name = tree.getAttachment(OriginalName).orElse(Some(tree.name))
100+
unusedDataApply(_.registerUsed(tree.symbol, name))
100101

101102
override def prepareForBlock(tree: tpd.Block)(using Context): Context =
102103
pushInBlockTemplatePackageDef(tree)
@@ -327,6 +328,8 @@ object CheckUnused:
327328
*/
328329
private val _key = Property.StickyKey[UnusedData]
329330

331+
val OriginalName = Property.StickyKey[Name]
332+
330333
class PostTyper extends CheckUnused(PhaseMode.Aggregate, "PostTyper", _key)
331334

332335
class PostInlining extends CheckUnused(PhaseMode.Report, "PostInlining", _key)

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import NullOpsDecorator.*
5151
import cc.{CheckCaptures, isRetainsLike}
5252
import config.Config
5353
import config.MigrationVersion
54+
import transform.CheckUnused.OriginalName
5455

5556
import scala.annotation.constructorOnly
5657

@@ -629,7 +630,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
629630
val checkedType = checkNotShadowed(ownType)
630631
val tree1 = checkedType match
631632
case checkedType: NamedType if !prefixIsElidable(checkedType) =>
632-
ref(checkedType).withSpan(tree.span)
633+
ref(checkedType).withSpan(tree.span).withAttachment(OriginalName, name)
633634
case _ =>
634635
def isScalaModuleRef = checkedType match
635636
case moduleRef: TypeRef if moduleRef.symbol.is(ModuleClass, butNot = JavaDefined) => true

0 commit comments

Comments
 (0)