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

REPL doesn't compute import renames correctly #7953

Open
scabug opened this Issue Nov 6, 2013 · 4 comments

Comments

Projects
None yet
2 participants
@scabug
Copy link

scabug commented Nov 6, 2013

Imports have a source name and the name (possibly a rename) to bring into scope. The algo in REPL to decide what to import is tripped up by the import handler not distinguishing them correctly. In the sample, normally it would bump the first import to an outer scope (and let normal shadowing effectively eliminate it). (Open question whether that inefficiency has any benefit; it doesn't try to nuance anything.)

apm@mara:~/projects/edge$ scalam
Welcome to Scala version 2.11.0-M5 (OpenJDK 64-Bit Server VM, Java 1.7.0_25).
Type in expressions to have them evaluated.
Type :help for more information.

scala> object Foo { def bar = 7 }
defined object Foo

scala> object Junk { val x = 7 }
defined object Junk

scala> import Foo.{ bar => baz }
import Foo.{bar=>baz}

scala> import Junk.{x=>baz}
import Junk.{x=>baz}

scala> baz
<console>:12: error: reference to baz is ambiguous;
it is imported twice in the same scope by
import Junk.{x=>baz}
and import Foo.{bar=>baz}
              baz
              ^
@scabug

This comment has been minimized.

Copy link
Author

scabug commented Nov 6, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7953?orig=1
Reporter: @som-snytt
Affected Versions: 2.11.0-M6

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Nov 7, 2013

@paulp said:
"Open question whether that inefficiency has any benefit; it doesn't try to nuance anything."

Having tried, I'll tell you it's harder than it looks to incrementally improve on the current approach, because it's tricky to be sure you can omit an import entirely. Wildcard imports with lower scope, implicits, renames, and then there is the little feature where a name might be shadowed in only one namespace, like this:

object Foo {
  class Bar
  object Bar
}
object Quux {
  class Bar
}

object Test {
  import Foo.Bar

  def main(args: Array[String]): Unit = {
    import Quux.Bar
    new Bar
    Bar
  }
}
@scabug

This comment has been minimized.

Copy link
Author

scabug commented Apr 19, 2015

Li Haoyi (lihaoyi) said:
This has been fixed in the Ammonite REPL.

@  object Foo { def bar = 7 }
defined object Foo
@  object Junk { val x = 7 }
defined object Junk
@ import Foo.{ bar => baz }
import Foo.{ bar => baz }
@  import Junk.{x=>baz}
import import Junk.{x=>baz}
@ baz
res24: Int = 7
@ object Foo { def bar = 7 }
defined object Foo
@ object Junk { val x = 8 }
defined object Junk
@ import Foo.{ bar => baz }
import Foo.{ bar => baz }
@ import Junk.{x=>baz}
import Junk.{x=>baz}
@ baz
res29: Int = 8
@
@scabug

This comment has been minimized.

Copy link
Author

scabug commented Nov 19, 2015

@paulp said:
For the usual value of "fixed" as seen here: lihaoyi/Ammonite#199

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment