Skip to content

Commit 6dcb45c

Browse files
committed
If there is an import selection for an indent, attach the original name
[Cherry-picked 72894aa][modified]
1 parent 319d2c6 commit 6dcb45c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ class CheckUnused private (phaseMode: CheckUnused.PhaseMode, suffix: String, _ke
9797
ctx
9898

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

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

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

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import Nullables.*
5050
import NullOpsDecorator.*
5151
import cc.CheckCaptures
5252
import config.Config
53+
import transform.CheckUnused.OriginalName
5354

5455
import scala.annotation.constructorOnly
5556
import dotty.tools.dotc.rewrites.Rewrites
@@ -619,7 +620,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
619620
val checkedType = checkNotShadowed(ownType)
620621
val tree1 = checkedType match
621622
case checkedType: NamedType if !prefixIsElidable(checkedType) =>
622-
ref(checkedType).withSpan(tree.span)
623+
ref(checkedType).withSpan(tree.span).withAttachment(OriginalName, name)
623624
case _ =>
624625
tree.withType(checkedType)
625626
val tree2 = toNotNullTermRef(tree1, pt)

0 commit comments

Comments
 (0)