diff options
-rw-r--r-- | src/dotty/tools/dotc/transform/PostTyper.scala | 13 | ||||
-rw-r--r-- | tests/neg/i1286.scala | 16 | ||||
-rw-r--r-- | tests/repl/imports.check | 10 |
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 51851a589..12d48d98e 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 000000000..40db9ab1d --- /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 26b725637..b6d9ae8a7 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 |