Skip to content

Commit e5d4be3

Browse files
committed
Fix WUnused false positive in for
1 parent d577300 commit e5d4be3

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ object CheckUnused:
473473
if ctx.settings.WunusedHas.explicits then
474474
explicitParamInScope
475475
.filterNot(d => d.symbol.usedDefContains)
476+
.filterNot(d => usedInPosition.exists { case (pos, name) => d.span.contains(pos.span) && name == d.symbol.name})
476477
.filterNot(d => containsSyntheticSuffix(d.symbol))
477478
.map(d => d.namePos -> WarnTypes.ExplicitParams).toList
478479
else

tests/neg-custom-args/fatal-warnings/i15503i.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,13 @@ package foo.test.i17156:
287287
package c:
288288
import b.Xd
289289
trait Z derives Xd
290+
291+
package foo.test.i17175:
292+
val continue = true
293+
def foo =
294+
for {
295+
i <- 1.until(10) // OK
296+
if continue
297+
} {
298+
println(i)
299+
}

0 commit comments

Comments
 (0)