aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Stucki <nicolas.stucki@gmail.com>2016-08-26 10:07:19 +0200
committerNicolas Stucki <nicolas.stucki@gmail.com>2016-10-21 09:16:32 +0200
commita8136fff2cc2f7c75f0a6253db79c3e339f56c98 (patch)
tree8c99fb1e84d06585891bcd9444242a0fcff3aa86
parent6070cce6a7887b6b3c65421bf0c37c92aec3182e (diff)
downloaddotty-a8136fff2cc2f7c75f0a6253db79c3e339f56c98.zip
dotty-a8136fff2cc2f7c75f0a6253db79c3e339f56c98.tar.gz
dotty-a8136fff2cc2f7c75f0a6253db79c3e339f56c98.tar.bz2
Fix #1286: Error on inexistent imports that are not used.
This commit also fixes #1583.
-rw-r--r--src/dotty/tools/dotc/transform/PostTyper.scala13
-rw-r--r--tests/neg/i1286.scala16
-rw-r--r--tests/repl/imports.check10
3 files changed, 39 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/transform/PostTyper.scala b/src/dotty/tools/dotc/transform/PostTyper.scala
index 51851a5..12d48d9 100644
--- a/src/dotty/tools/dotc/transform/PostTyper.scala
+++ b/src/dotty/tools/dotc/transform/PostTyper.scala
@@ -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)
}
diff --git a/tests/neg/i1286.scala b/tests/neg/i1286.scala
new file mode 100644
index 0000000..40db9ab
--- /dev/null
+++ b/tests/neg/i1286.scala
@@ -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
diff --git a/tests/repl/imports.check b/tests/repl/imports.check
index 26b7256..b6d9ae8 100644
--- a/tests/repl/imports.check
+++ b/tests/repl/imports.check
@@ -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