@@ -3,11 +3,10 @@ package scala.async.run.late
3
3
import java .io .File
4
4
5
5
import junit .framework .Assert .assertEquals
6
- import org .junit .{Assert , Test }
6
+ import org .junit .{Assert , Ignore , Test }
7
7
8
8
import scala .annotation .StaticAnnotation
9
9
import scala .annotation .meta .{field , getter }
10
- import scala .async .TreeInterrogation
11
10
import scala .async .internal .AsyncId
12
11
import scala .reflect .internal .util .ScalaClassLoader .URLClassLoader
13
12
import scala .tools .nsc ._
@@ -19,6 +18,57 @@ import scala.tools.nsc.transform.TypingTransformers
19
18
// calls it from a new phase that runs after patmat.
20
19
class LateExpansion {
21
20
21
+ @ Test def testRewrittenApply (): Unit = {
22
+ val result = wrapAndRun(
23
+ """
24
+ | object O {
25
+ | case class Foo(a: Any)
26
+ | }
27
+ | @autoawait def id(a: String) = a
28
+ | O.Foo
29
+ | id("foo") + id("bar")
30
+ | O.Foo(1)
31
+ | """ .stripMargin)
32
+ assertEquals(" Foo(1)" , result.toString)
33
+ }
34
+
35
+ @ Ignore (" Need to use adjustType more pervasively in AsyncTransform, but that exposes bugs in {Type, ... }Symbol's cache invalidation" )
36
+ @ Test def testIsInstanceOfType (): Unit = {
37
+ val result = wrapAndRun(
38
+ """
39
+ | class Outer
40
+ | @autoawait def id(a: String) = a
41
+ | val o = new Outer
42
+ | id("foo") + id("bar")
43
+ | ("": Object).isInstanceOf[o.type]
44
+ | """ .stripMargin)
45
+ assertEquals(false , result)
46
+ }
47
+
48
+ @ Test def testIsInstanceOfTerm (): Unit = {
49
+ val result = wrapAndRun(
50
+ """
51
+ | class Outer
52
+ | @autoawait def id(a: String) = a
53
+ | val o = new Outer
54
+ | id("foo") + id("bar")
55
+ | o.isInstanceOf[Outer]
56
+ | """ .stripMargin)
57
+ assertEquals(true , result)
58
+ }
59
+
60
+ @ Test def testArrayLocalModule (): Unit = {
61
+ val result = wrapAndRun(
62
+ """
63
+ | class Outer
64
+ | @autoawait def id(a: String) = a
65
+ | val O = ""
66
+ | id("foo") + id("bar")
67
+ | new Array[O.type](0)
68
+ | """ .stripMargin)
69
+ assertEquals(classOf [Array [String ]], result.getClass)
70
+ }
71
+
22
72
@ Test def test0 (): Unit = {
23
73
val result = wrapAndRun(
24
74
"""
@@ -27,6 +77,7 @@ class LateExpansion {
27
77
| """ .stripMargin)
28
78
assertEquals(" foobar" , result)
29
79
}
80
+
30
81
@ Test def testGuard (): Unit = {
31
82
val result = wrapAndRun(
32
83
"""
@@ -143,6 +194,7 @@ class LateExpansion {
143
194
|}
144
195
| """ .stripMargin)
145
196
}
197
+
146
198
@ Test def shadowing2 (): Unit = {
147
199
val result = run(
148
200
"""
@@ -369,6 +421,7 @@ class LateExpansion {
369
421
}
370
422
""" )
371
423
}
424
+
372
425
@ Test def testNegativeArraySizeExceptionFine1 (): Unit = {
373
426
val result = run(
374
427
"""
@@ -389,18 +442,20 @@ class LateExpansion {
389
442
}
390
443
""" )
391
444
}
445
+
392
446
private def createTempDir (): File = {
393
447
val f = File .createTempFile(" output" , " " )
394
448
f.delete()
395
449
f.mkdirs()
396
450
f
397
451
}
452
+
398
453
def run (code : String ): Any = {
399
- // settings.processArgumentString("-Xprint:patmat,postpatmat,jvm -Ybackend:GenASM -nowarn")
400
454
val out = createTempDir()
401
455
try {
402
456
val reporter = new StoreReporter
403
457
val settings = new Settings (println(_))
458
+ // settings.processArgumentString("-Xprint:refchecks,patmat,postpatmat,jvm -nowarn")
404
459
settings.outdir.value = out.getAbsolutePath
405
460
settings.embeddedDefaults(getClass.getClassLoader)
406
461
val isInSBT = ! settings.classpath.isSetByUser
@@ -432,6 +487,7 @@ class LateExpansion {
432
487
}
433
488
434
489
abstract class LatePlugin extends Plugin {
490
+
435
491
import global ._
436
492
437
493
override val components : List [PluginComponent ] = List (new PluginComponent with TypingTransformers {
@@ -448,16 +504,16 @@ abstract class LatePlugin extends Plugin {
448
504
super .transform(tree) match {
449
505
case ap@ Apply (fun, args) if fun.symbol.hasAnnotation(autoAwaitSym) =>
450
506
localTyper.typed(Apply (TypeApply (gen.mkAttributedRef(asyncIdSym.typeOfThis, awaitSym), TypeTree (ap.tpe) :: Nil ), ap :: Nil ))
451
- case sel@ Select (fun, _) if sel.symbol.hasAnnotation(autoAwaitSym) && ! (tree.tpe.isInstanceOf [MethodTypeApi ] || tree.tpe.isInstanceOf [PolyTypeApi ] ) =>
507
+ case sel@ Select (fun, _) if sel.symbol.hasAnnotation(autoAwaitSym) && ! (tree.tpe.isInstanceOf [MethodTypeApi ] || tree.tpe.isInstanceOf [PolyTypeApi ]) =>
452
508
localTyper.typed(Apply (TypeApply (gen.mkAttributedRef(asyncIdSym.typeOfThis, awaitSym), TypeTree (sel.tpe) :: Nil ), sel :: Nil ))
453
509
case dd : DefDef if dd.symbol.hasAnnotation(lateAsyncSym) => atOwner(dd.symbol) {
454
- deriveDefDef(dd){ rhs : Tree =>
510
+ deriveDefDef(dd) { rhs : Tree =>
455
511
val invoke = Apply (TypeApply (gen.mkAttributedRef(asyncIdSym.typeOfThis, asyncSym), TypeTree (rhs.tpe) :: Nil ), List (rhs))
456
512
localTyper.typed(atPos(dd.pos)(invoke))
457
513
}
458
514
}
459
515
case vd : ValDef if vd.symbol.hasAnnotation(lateAsyncSym) => atOwner(vd.symbol) {
460
- deriveValDef(vd){ rhs : Tree =>
516
+ deriveValDef(vd) { rhs : Tree =>
461
517
val invoke = Apply (TypeApply (gen.mkAttributedRef(asyncIdSym.typeOfThis, asyncSym), TypeTree (rhs.tpe) :: Nil ), List (rhs))
462
518
localTyper.typed(atPos(vd.pos)(invoke))
463
519
}
@@ -468,6 +524,7 @@ abstract class LatePlugin extends Plugin {
468
524
}
469
525
}
470
526
}
527
+
471
528
override def newPhase (prev : Phase ): Phase = new StdPhase (prev) {
472
529
override def apply (unit : CompilationUnit ): Unit = {
473
530
val translated = newTransformer(unit).transformUnit(unit)
@@ -476,7 +533,7 @@ abstract class LatePlugin extends Plugin {
476
533
}
477
534
}
478
535
479
- override val runsAfter : List [String ] = " patmat " :: Nil
536
+ override val runsAfter : List [String ] = " refchecks " :: Nil
480
537
override val phaseName : String = " postpatmat"
481
538
482
539
})
0 commit comments