Skip to content

Commit 2ed1f1f

Browse files
committed
Warn unused Imports methods overload
- overloaded where not well resolved and thus not reported - also add a tests
1 parent 5a755dd commit 2ed1f1f

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class CheckUnused extends Phase:
7676
case sel: Select =>
7777
unusedDataApply(_.registerUsed(sel.symbol))
7878
traverseChildren(tree)(using newCtx)
79-
case _: (tpd.Block | tpd.Template) =>
79+
case _: (tpd.Block | tpd.Template | tpd.PackageDef) =>
8080
unusedDataApply { ud =>
8181
ud.inNewScope(ScopeType.fromTree(tree))(traverseChildren(tree)(using newCtx))
8282
}

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,27 @@ package testImportsInImports:
213213
package c:
214214
import a.b // OK
215215
import b.x // OK
216-
val y = x
216+
val y = x
217+
218+
//-------------------------------------
219+
package testOnOverloadedMethodsImports:
220+
package a:
221+
trait A
222+
trait B
223+
trait C:
224+
def foo(x: A):A = ???
225+
def foo(x: B):B = ???
226+
package b:
227+
object D extends a.C
228+
package c:
229+
import b.D.foo // error
230+
package d:
231+
import b.D.foo // OK
232+
def bar = foo((??? : a.A))
233+
package e:
234+
import b.D.foo // OK
235+
def bar = foo((??? : a.B))
236+
package f:
237+
import b.D.foo // OK
238+
def bar = foo((??? : a.A))
239+
def baz = foo((??? : a.B))

0 commit comments

Comments
 (0)