File tree 6 files changed +57
-1
lines changed
6 files changed +57
-1
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,11 @@ class ReplCompiler extends Compiler:
46
46
/** Import previous runs and user defined imports */
47
47
override protected def rootContext (using Context ): Context = {
48
48
def importContext (imp : tpd.Import )(using Context ) =
49
- ctx.importContext(imp, imp.symbol)
49
+ // TODO: only when context has changed?
50
+ val typer = ctx.typer
51
+ typer.index(imp)
52
+ val imp2 = typer.typed(imp).asInstanceOf [tpd.Import ]
53
+ ctx.importContext(imp2, imp2.symbol)
50
54
51
55
def importPreviousRun (id : Int )(using Context ) = {
52
56
// 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