Skip to content

I can't unimport names under scala package object #11317

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

Closed
eed3si9n opened this issue Dec 17, 2018 · 2 comments
Closed

I can't unimport names under scala package object #11317

eed3si9n opened this issue Dec 17, 2018 · 2 comments

Comments

@eed3si9n
Copy link
Member

steps

I want to mask scala.Seq.

scala> :paste
// Entering paste mode (ctrl-D to finish)

object Foo {
  import scala.{ Seq => _, _ }
  val xs = Seq(1, 2, 3)
}

// Exiting paste mode, now interpreting.

defined object Foo

scala> Foo.xs
res1: Seq[Int] = List(1, 2, 3)

problem

The name Seq is still available within object Foo { ... }.

expectation

The code does not compile.

@Jasper-M
Copy link

Jasper-M commented Dec 17, 2018

It's generally not possible to unimport something after it has already been imported:

scala> def foo = {
     |   import scala.util._
     |   import scala.util.{Try => _, _}
     |   Try(1/0)
     | }
foo: scala.util.Try[Int]

Also see:

-Yimports:<import>                       Custom root imports, default is `java.lang,scala,scala.Predef`.
-Yno-imports                             Compile without importing scala.*, java.lang.*, or Predef.
-Yno-predef                              Compile without importing Predef.

@eed3si9n
Copy link
Member Author

It's generally not possible to unimport something after it has already been imported

Trying to tie this back to the spec.

2 says:

A binding in some inner scope shadows bindings of lower precedence in the same scope as well as bindings of the same or lower precedence in outer scopes.

I guess in my example, the unqualified Seq would not be bound in object Foo scope, so it would try the outer scope of that and finds import scala._ in there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants