@@ -66,14 +66,14 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
66
66
// import x.y; y may be rewritten x.y, also import x.z as y
67
67
override def transformSelect (tree : Select )(using Context ): tree.type =
68
68
val name = tree.removeAttachment(OriginalName ).getOrElse(nme.NO_NAME )
69
- if tree.span .isSynthetic && tree.symbol == defn.TypeTest_unapply then
69
+ if tree.srcPos .isSynthetic && tree.symbol == defn.TypeTest_unapply then
70
70
tree.qualifier.tpe.underlying.finalResultType match
71
71
case AppliedType (_, args) => // tycon.typeSymbol == defn.TypeTestClass
72
72
val res = args(1 ) // T in TypeTest[-S, T]
73
73
val target = res.dealias.typeSymbol
74
74
resolveUsage(target, target.name, res.importPrefix.skipPackageObject) // case _: T =>
75
75
case _ =>
76
- else if tree.qualifier.span .isSynthetic || name.exists(_ != tree.symbol.name) then
76
+ else if tree.qualifier.srcPos .isSynthetic || name.exists(_ != tree.symbol.name) then
77
77
if ! ignoreTree(tree) then
78
78
resolveUsage(tree.symbol, name, tree.qualifier.tpe)
79
79
else
@@ -592,12 +592,12 @@ object CheckUnused:
592
592
warnAt(pos)(UnusedSymbol .localDefs)
593
593
594
594
def checkPatvars () =
595
- // convert the one non-synthetic span so all are comparable
595
+ // convert the one non-synthetic span so all are comparable; filter NoSpan below
596
596
def uniformPos (sym : Symbol , pos : SrcPos ): SrcPos =
597
597
if pos.span.isSynthetic then pos else pos.sourcePos.withSpan(pos.span.toSynthetic)
598
598
// patvars in for comprehensions share the pos of where the name was introduced
599
599
val byPos = infos.pats.groupMap(uniformPos(_, _))((sym, pos) => sym)
600
- for (pos, syms) <- byPos if ! syms.exists(_.hasAnnotation(defn.UnusedAnnot )) do
600
+ for (pos, syms) <- byPos if pos.span.exists && ! syms.exists(_.hasAnnotation(defn.UnusedAnnot )) do
601
601
if ! syms.exists(infos.refs(_)) then
602
602
if ! syms.exists(v => ! v.isLocal && ! v.is(Private )) then
603
603
warnAt(pos)(UnusedSymbol .patVars)
@@ -658,7 +658,10 @@ object CheckUnused:
658
658
val selector = textAt(sel.srcPos) // keep original
659
659
s " $qual. $selector" // don't succumb to vagaries of show
660
660
// begin actionable
661
- val sortedImps = infos.imps.keySet.nn.asScala.toArray.sortBy(_.srcPos.span.point) // sorted by pos
661
+ val sortedImps = infos.imps.keySet.nn.asScala
662
+ .filter(_.srcPos.span.exists) // extra caution
663
+ .toArray
664
+ .sortBy(_.srcPos.span.point) // sorted by pos, not sort in place
662
665
var index = 0
663
666
while index < sortedImps.length do
664
667
val nextImport = sortedImps.indexSatisfying(from = index + 1 )(_.isPrimaryClause) // next import statement
@@ -757,7 +760,11 @@ object CheckUnused:
757
760
if ctx.settings.WunusedHas .imports || ctx.settings.WunusedHas .strictNoImplicitWarn then
758
761
checkImports()
759
762
760
- warnings.result().sortBy(_._2.span.point)
763
+ def sortOrder (msgInfo : MessageInfo ): Int =
764
+ val srcPos = msgInfo._2
765
+ if srcPos.span.exists then srcPos.span.point else 0
766
+
767
+ warnings.result().sortBy(sortOrder)
761
768
end warnings
762
769
763
770
// Specific exclusions
@@ -881,8 +888,7 @@ object CheckUnused:
881
888
extension (imp : Import )
882
889
/** Is it the first import clause in a statement? `a.x` in `import a.x, b.{y, z}` */
883
890
def isPrimaryClause (using Context ): Boolean =
884
- val span = imp.srcPos.span
885
- span.start != span.point // primary clause starts at `import` keyword
891
+ imp.srcPos.span.pointDelta > 0 // primary clause starts at `import` keyword with point at clause proper
886
892
887
893
/** Generated import of cases from enum companion. */
888
894
def isGeneratedByEnum (using Context ): Boolean =
@@ -905,6 +911,7 @@ object CheckUnused:
905
911
906
912
extension (pos : SrcPos )
907
913
def isZeroExtentSynthetic : Boolean = pos.span.isSynthetic && pos.span.isZeroExtent
914
+ def isSynthetic : Boolean = pos.span.isSynthetic && pos.span.exists
908
915
909
916
extension [A <: AnyRef ](arr : Array [A ])
910
917
// returns `until` if not satisfied
0 commit comments