Skip to content

Commit c738655

Browse files
committed
Fix #1286: Warn on inexistent imports that are not used.
1 parent 959ea0c commit c738655

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/dotty/tools/dotc/transform/PostTyper.scala

+12
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,18 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
274274
case tpe => tpe
275275
}
276276
)
277+
case Import(expr, selectors) =>
278+
val exprTpe = expr.tpe
279+
def notExists(name: Name): Boolean =
280+
name != nme.WILDCARD && !exprTpe.member(name).exists
281+
selectors.foreach {
282+
case ident @ Ident(name) if notExists(name) =>
283+
ctx.warning(s"$name is not a member of ${expr.show}", ident.pos)
284+
case Pair(ident @ Ident(name), _) if notExists(name) =>
285+
ctx.warning(s"$name is not a member of ${expr.show}", ident.pos)
286+
case _ =>
287+
}
288+
super.transform(tree)
277289
case tree =>
278290
super.transform(tree)
279291
}

tests/pos/i1286.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import scala.idontexist // warn
2+
import scala.io.Idontexist // warn
3+
4+
import scala.io
5+
import io.Idontexist2 // warn
6+
7+
import scala.io.{ AnsiColor, Idontexist3 } // warn
8+
9+
import scala.io.{ Idontexist4 => Foo } // warn
10+
import scala.io.{ Idontexist5 => _ } // warn
11+
12+
object Test

0 commit comments

Comments
 (0)