File tree Expand file tree Collapse file tree 6 files changed +57
-1
lines changed Expand file tree Collapse file tree 6 files changed +57
-1
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,11 @@ class ReplCompiler extends Compiler:
4747 /** Import previous runs and user defined imports */
4848 override protected def rootContext (using Context ): Context = {
4949 def importContext (imp : tpd.Import )(using Context ) =
50- ctx.importContext(imp, imp.symbol)
50+ // TODO: only when context has changed?
51+ val typer = ctx.typer
52+ typer.index(imp)
53+ val imp2 = typer.typed(imp).asInstanceOf [tpd.Import ]
54+ ctx.importContext(imp2, imp2.symbol)
5155
5256 def importPreviousRun (id : Int )(using Context ) = {
5357 // we first import the wrapper object id
Original file line number Diff line number Diff line change 1+ // MyLibrary.scala
2+ package mylibrary
3+
4+ object Utils :
5+ def greet (name : String ): String = s " Hello, $name! "
6+
7+ class Calculator :
8+ def add (x : Int , y : Int ): Int = x + y
9+ def subtract (x : Int , y : Int ): Int = x - y
10+
Original file line number Diff line number Diff line change 1+ // MyLibrary2.scala
2+ package mylibrary2
3+
4+ object Utils2 :
5+ def greet (name : String ): String = s " Hello, $name! "
6+
7+ class Calculator2 :
8+ def add (x : Int , y : Int ): Int = x + y
9+ def subtract (x : Int , y : Int ): Int = x - y
10+
Original file line number Diff line number Diff line change 1+ scala> val z = 1
2+ val z: Int = 1
3+
4+ scala>:require compiler/test-resources/jars/mylibrary.jar
5+ Added 'compiler/test-resources/jars/mylibrary.jar' to classpath.
6+
7+ scala> import mylibrary.Utils
8+
9+ scala> Utils.greet("Alice")
10+ val res0: String = Hello, Alice!
11+
12+ scala>:require compiler/test-resources/jars/mylibrary2.jar
13+ Added 'compiler/test-resources/jars/mylibrary2.jar' to classpath.
14+
15+ scala> import mylibrary2.Utils2
16+
17+ scala> Utils2.greet("Alice")
18+ val res1: String = Hello, Alice!
19+
20+ scala> Utils.greet("Alice")
21+ val res2: String = Hello, Alice!
22+
23+ scala> import mylibrary.Utils.greet
24+
25+ scala> greet("Tom")
26+ val res3: String = Hello, Tom!
27+
28+ scala> Utils.greet("Alice")
29+ val res4: String = Hello, Alice!
30+
31+ scala> z
32+ val res5: Int = 1
You can’t perform that action at this time.
0 commit comments