Skip to content

Commit f993782

Browse files
committed
Fix warning location
- Fix the position of unused warning (unused locals, unused privates) to the declaration name. This avoids hidden overlapping warning
1 parent a1c2bae commit f993782

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,11 @@ class CheckUnused extends Phase:
106106
res.foreach { s =>
107107
s match
108108
case (t, WarnTypes.Imports) =>
109-
println("hey")
110109
report.warning(s"unused import", t)
111110
case (t, WarnTypes.LocalDefs) =>
112-
report.warning(s"unused local definition", t.startPos)
111+
report.warning(s"unused local definition", t)
113112
case (t, WarnTypes.PrivateMembers) =>
114-
report.warning(s"unused private member", t.startPos)
113+
report.warning(s"unused private member", t)
115114
}
116115

117116
end CheckUnused
@@ -246,12 +245,12 @@ object CheckUnused:
246245
Nil
247246
val sortedLocalDefs =
248247
if ctx.settings.WunusedHas.locals then
249-
unusedLocalDef.map(d => d.srcPos -> WarnTypes.LocalDefs).toList
248+
unusedLocalDef.map(d => d.withSpan(d.span.withEnd(d.tpt.startPos.start)) -> WarnTypes.LocalDefs).toList
250249
else
251250
Nil
252251
val sortedPrivateDefs =
253252
if ctx.settings.WunusedHas.privates then
254-
unusedPrivateDef.map(d => d.srcPos -> WarnTypes.PrivateMembers).toList
253+
unusedPrivateDef.map(d => d.withSpan(d.span.withEnd(d.tpt.startPos.start)) -> WarnTypes.PrivateMembers).toList
255254
else
256255
Nil
257256
List(sortedImp, sortedLocalDefs, sortedPrivateDefs).flatten.sortBy { s =>

0 commit comments

Comments
 (0)