Skip to content

Fix #1286: Warn on inexistent imports that are not used. #1479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/dotty/tools/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,19 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
case tpe => tpe
}
)
case Import(expr, selectors) =>
val exprTpe = expr.tpe
def checkIdent(ident: Ident): Unit = {
val name = ident.name.asTermName.encode
if (name != nme.WILDCARD && !exprTpe.member(name).exists && !exprTpe.member(name.toTypeName).exists)
ctx.error(s"${ident.name} is not a member of ${expr.show}", ident.pos)
}
selectors.foreach {
case ident: Ident => checkIdent(ident)
case Thicket((ident: Ident) :: _) => checkIdent(ident)
case _ =>
}
super.transform(tree)
case tree =>
super.transform(tree)
}
Expand Down
16 changes: 16 additions & 0 deletions tests/neg/i1286.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import scala.idontexist // error
import scala.io.Idontexist // error

import scala.io
import io.Idontexist2 // error

import scala.io.{ AnsiColor, Idontexist3 } // error

import scala.io.{ Idontexist4 => Foo } // error
import scala.io.{ Idontexist5 => _ } // error

import scala.language.dynamics
import scala.language.noAutoTupling
import scala.language.idontexist // error

object Test
10 changes: 10 additions & 0 deletions tests/repl/imports.check
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,14 @@ scala> buf += xs
|
scala> buf ++= xs
res1: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 2, 3)
scala> import util.foo
-- Error: <console> ----------------------------------------------------------------------------------------------------
8 |import util.foo
| ^^^
| foo is not a member of util
scala> import util.foo.bar
-- [E008] Member Not Found Error: <console> ----------------------------------------------------------------------------
8 |import util.foo.bar
| ^^^^^^^^
| value `foo` is not a member of util.type - did you mean `util.Left`?
scala> :quit