Skip to content
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

Closed
scabug opened this issue Nov 6, 2013 · 5 comments
Closed

REPL doesn't compute import renames correctly #7953

scabug opened this issue Nov 6, 2013 · 5 comments
Labels

Comments

@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
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
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
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
Copy link
Author

scabug commented Nov 19, 2015

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

@som-snytt
Copy link

Closing as duplicate of linked ticket which fixed it. Hashtag fixit ticket.

@som-snytt som-snytt closed this as not planned Won't fix, can't repro, duplicate, stale Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants