@@ -7,7 +7,6 @@ import org.junit.{Assert, 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,56 @@ 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
+ @ Test def testIsInstanceOfType (): Unit = {
36
+ val result = wrapAndRun(
37
+ """
38
+ | class Outer
39
+ | @autoawait def id(a: String) = a
40
+ | val o = new Outer
41
+ | id("foo") + id("bar")
42
+ | ("": Object).isInstanceOf[o.type]
43
+ | """ .stripMargin)
44
+ assertEquals(false , result)
45
+ }
46
+
47
+ @ Test def testIsInstanceOfTerm (): Unit = {
48
+ val result = wrapAndRun(
49
+ """
50
+ | class Outer
51
+ | @autoawait def id(a: String) = a
52
+ | val o = new Outer
53
+ | id("foo") + id("bar")
54
+ | o.isInstanceOf[Outer]
55
+ | """ .stripMargin)
56
+ assertEquals(true , result)
57
+ }
58
+
59
+ @ Test def testArrayLocalModule (): Unit = {
60
+ val result = wrapAndRun(
61
+ """
62
+ | class Outer
63
+ | @autoawait def id(a: String) = a
64
+ | val O = ""
65
+ | id("foo") + id("bar")
66
+ | new Array[O.type](0)
67
+ | """ .stripMargin)
68
+ assertEquals(classOf [Array [String ]], result.getClass)
69
+ }
70
+
22
71
@ Test def test0 (): Unit = {
23
72
val result = wrapAndRun(
24
73
"""
@@ -27,6 +76,7 @@ class LateExpansion {
27
76
| """ .stripMargin)
28
77
assertEquals(" foobar" , result)
29
78
}
79
+
30
80
@ Test def testGuard (): Unit = {
31
81
val result = wrapAndRun(
32
82
"""
@@ -143,6 +193,7 @@ class LateExpansion {
143
193
|}
144
194
| """ .stripMargin)
145
195
}
196
+
146
197
@ Test def shadowing2 (): Unit = {
147
198
val result = run(
148
199
"""
@@ -369,6 +420,7 @@ class LateExpansion {
369
420
}
370
421
""" )
371
422
}
423
+
372
424
@ Test def testNegativeArraySizeExceptionFine1 (): Unit = {
373
425
val result = run(
374
426
"""
@@ -389,18 +441,20 @@ class LateExpansion {
389
441
}
390
442
""" )
391
443
}
444
+
392
445
private def createTempDir (): File = {
393
446
val f = File .createTempFile(" output" , " " )
394
447
f.delete()
395
448
f.mkdirs()
396
449
f
397
450
}
451
+
398
452
def run (code : String ): Any = {
399
- // settings.processArgumentString("-Xprint:patmat,postpatmat,jvm -Ybackend:GenASM -nowarn")
400
453
val out = createTempDir()
401
454
try {
402
455
val reporter = new StoreReporter
403
456
val settings = new Settings (println(_))
457
+ // settings.processArgumentString("-Xprint:refchecks,patmat,postpatmat,jvm -nowarn")
404
458
settings.outdir.value = out.getAbsolutePath
405
459
settings.embeddedDefaults(getClass.getClassLoader)
406
460
val isInSBT = ! settings.classpath.isSetByUser
@@ -432,6 +486,7 @@ class LateExpansion {
432
486
}
433
487
434
488
abstract class LatePlugin extends Plugin {
489
+
435
490
import global ._
436
491
437
492
override val components : List [PluginComponent ] = List (new PluginComponent with TypingTransformers {
@@ -448,16 +503,16 @@ abstract class LatePlugin extends Plugin {
448
503
super .transform(tree) match {
449
504
case ap@ Apply (fun, args) if fun.symbol.hasAnnotation(autoAwaitSym) =>
450
505
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 ] ) =>
506
+ case sel@ Select (fun, _) if sel.symbol.hasAnnotation(autoAwaitSym) && ! (tree.tpe.isInstanceOf [MethodTypeApi ] || tree.tpe.isInstanceOf [PolyTypeApi ]) =>
452
507
localTyper.typed(Apply (TypeApply (gen.mkAttributedRef(asyncIdSym.typeOfThis, awaitSym), TypeTree (sel.tpe) :: Nil ), sel :: Nil ))
453
508
case dd : DefDef if dd.symbol.hasAnnotation(lateAsyncSym) => atOwner(dd.symbol) {
454
- deriveDefDef(dd){ rhs : Tree =>
509
+ deriveDefDef(dd) { rhs : Tree =>
455
510
val invoke = Apply (TypeApply (gen.mkAttributedRef(asyncIdSym.typeOfThis, asyncSym), TypeTree (rhs.tpe) :: Nil ), List (rhs))
456
511
localTyper.typed(atPos(dd.pos)(invoke))
457
512
}
458
513
}
459
514
case vd : ValDef if vd.symbol.hasAnnotation(lateAsyncSym) => atOwner(vd.symbol) {
460
- deriveValDef(vd){ rhs : Tree =>
515
+ deriveValDef(vd) { rhs : Tree =>
461
516
val invoke = Apply (TypeApply (gen.mkAttributedRef(asyncIdSym.typeOfThis, asyncSym), TypeTree (rhs.tpe) :: Nil ), List (rhs))
462
517
localTyper.typed(atPos(vd.pos)(invoke))
463
518
}
@@ -468,6 +523,7 @@ abstract class LatePlugin extends Plugin {
468
523
}
469
524
}
470
525
}
526
+
471
527
override def newPhase (prev : Phase ): Phase = new StdPhase (prev) {
472
528
override def apply (unit : CompilationUnit ): Unit = {
473
529
val translated = newTransformer(unit).transformUnit(unit)
@@ -476,7 +532,7 @@ abstract class LatePlugin extends Plugin {
476
532
}
477
533
}
478
534
479
- override val runsAfter : List [String ] = " patmat " :: Nil
535
+ override val runsAfter : List [String ] = " refchecks " :: Nil
480
536
override val phaseName : String = " postpatmat"
481
537
482
538
})
0 commit comments