This repository was archived by the owner on Sep 1, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +29
-6
lines changed
src/repl/scala/tools/nsc/interpreter Expand file tree Collapse file tree 5 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -166,15 +166,15 @@ trait Imports {
166
166
for (imv <- x.definedNames) {
167
167
if (! currentImps.contains(imv)) {
168
168
x match {
169
- case _ : ValHandler | _ : ModuleHandler =>
169
+ case _ : ClassHandler =>
170
+ code.append(" import " + objName + req.accessPath + " .`" + imv + " `\n " )
171
+ case _ =>
170
172
val valName = req.lineRep.packageName + req.lineRep.readName
171
173
if (! tempValLines.contains(req.lineRep.lineId)) {
172
174
code.append(s " val $valName = $objName\n " )
173
175
tempValLines += req.lineRep.lineId
174
176
}
175
- code.append(s " import $valName ${req.accessPath}.` $imv`; \n " )
176
- case _ =>
177
- code.append(" import " + objName + req.accessPath + " .`" + imv + " `\n " )
177
+ code.append(s " import $valName${req.accessPath}.` $imv`; \n " )
178
178
}
179
179
currentImps += imv
180
180
}
Original file line number Diff line number Diff line change 2
2
extract: AnyRef => Unit = <function1>
3
3
evaluating x
4
4
x: Int = 0
5
+ getX: ()Int
6
+ defined class U
5
7
y: Int = <lazy>
6
8
evaluating z
7
9
evaluating zz
@@ -11,6 +13,8 @@ zz: Int = 0
11
13
defined object O
12
14
defined class A
13
15
defined type alias AA
16
+ constructing U
17
+ u: U = U
14
18
== evaluating lambda
15
19
evaluating y
16
20
evaluating O
Original file line number Diff line number Diff line change @@ -25,12 +25,15 @@ object Test {
25
25
26
26
val code =
27
27
""" val x = {println(" evaluating x"); 0 }
28
+ |def getX() = x
29
+ |class U extends Serializable { println("constructing U"); val x = 0 ; override def toString = "U" }
28
30
|lazy val y = {println(" evaluating y"); 0 }
29
31
|class D; val z = {println(" evaluating z"); 0}; val zz = {println(" evaluating zz"); 0}
30
32
|object O extends Serializable { val apply = {println(" evaluating O"); 0} }
31
33
|class A(i: Int) { println(" constructing A") }
32
34
|type AA = A
33
- |extract(() => new AA(x + y + z + zz + O.apply))
35
+ |val u = new U()
36
+ |extract(() => new AA(x + getX() + y + z + zz + O.apply + u.x))
34
37
""" .stripMargin
35
38
36
39
imain = new IMain (settings)
Original file line number Diff line number Diff line change @@ -284,6 +284,18 @@ object $read extends scala.AnyRef {
284
284
}
285
285
res3: List[Product with Serializable] = List(BippyBups(), PuppyPups(), Bingo())
286
286
287
+ scala> case class Sum(exp: String, exp2: String)
288
+ defined class Sum
289
+
290
+ scala> val a = Sum("A", "B")
291
+ a: Sum = Sum(A,B)
292
+
293
+ scala> def b(a: Sum): String = a match { case Sum(_, _) => "Found Sum" }
294
+ b: (a: Sum)String
295
+
296
+ scala> b(a)
297
+ res4: String = Found Sum
298
+
287
299
scala> :power
288
300
** Power User mode enabled - BEEP WHIR GYVE **
289
301
** :phase has been set to 'typer'. **
@@ -292,6 +304,6 @@ scala> :power
292
304
** Try :help, :vals, power.<tab> **
293
305
294
306
scala> intp.lastRequest
295
- res4 : $r.intp.Request = Request(line=def $ires3 = intp.global, 1 trees)
307
+ res5 : $r.intp.Request = Request(line=def $ires3 = intp.global, 1 trees)
296
308
297
309
scala> :quit
Original file line number Diff line number Diff line change @@ -65,6 +65,10 @@ object Test extends ReplTest {
65
65
|case class PuppyPups()
66
66
|case class Bingo()
67
67
|List(BippyBups(), PuppyPups(), Bingo()) // show
68
+ |case class Sum(exp: String, exp2: String)
69
+ |val a = Sum("A", "B")
70
+ |def b(a: Sum): String = a match { case Sum(_, _) => "Found Sum" }
71
+ |b(a)
68
72
|:power
69
73
|intp.lastRequest
70
74
|""" .stripMargin
You can’t perform that action at this time.
0 commit comments