[SI-7953] REPL doesn't compute import renames correctly Created: 06/Nov/13  Updated: 13/Aug/16

Status: Open
Project: Scala Programming Language
Component/s: Repl / Interpreter
Affects Version/s: Scala 2.11.0-M6
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: A. P. Marki Assignee: Unassigned
Resolution: Unresolved Votes: 1
Labels: None

Issue Links:
Duplicate
is duplicated by SI-9881 REPL ImportHandler is not tracking im... CLOSED

 Description   

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
              ^



 Comments   
Comment by Paul Phillips [ 07/Nov/13 ]

"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
  }
}

Comment by Li Haoyi [ 19/Apr/15 ]

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
@

Comment by Paul Phillips [ 19/Nov/15 ]

For the usual value of "fixed" as seen here: https://github.com/lihaoyi/Ammonite/issues/199

Generated at Fri Oct 19 11:20:19 CEST 2018 using JIRA 7.9.1#79001-sha1:60970b42586a2ec2760ed6cfe825b26961e62b9e.