@@ -7,7 +7,7 @@ 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
10
+ import scala .async .TreeInterrogationApp
11
11
import scala .async .internal .AsyncId
12
12
import scala .reflect .internal .util .ScalaClassLoader .URLClassLoader
13
13
import scala .tools .nsc ._
@@ -27,6 +27,7 @@ class LateExpansion {
27
27
| """ .stripMargin)
28
28
assertEquals(" foobar" , result)
29
29
}
30
+
30
31
@ Test def testGuard (): Unit = {
31
32
val result = wrapAndRun(
32
33
"""
@@ -143,6 +144,7 @@ class LateExpansion {
143
144
|}
144
145
| """ .stripMargin)
145
146
}
147
+
146
148
@ Test def shadowing2 (): Unit = {
147
149
val result = run(
148
150
"""
@@ -366,6 +368,7 @@ class LateExpansion {
366
368
}
367
369
""" )
368
370
}
371
+
369
372
@ Test def testNegativeArraySizeExceptionFine1 (): Unit = {
370
373
val result = run(
371
374
"""
@@ -386,10 +389,35 @@ class LateExpansion {
386
389
}
387
390
""" )
388
391
}
392
+
393
+ @ Test def testNull (): Unit = {
394
+ val result = run(
395
+ """
396
+ import scala.async.run.late.{autoawait,lateasync}
397
+ case class FixedFoo(foo: Int)
398
+ class Foobar(val foo: Int, val bar: Double) {
399
+ def guard: Boolean = true
400
+ @autoawait @lateasync def getValue = 4.2
401
+ @autoawait @lateasync def func(f: Any) = {
402
+ ("": Any) match {
403
+ case (x1, y1) if guard => x1.toString; y1.toString
404
+ case (x2, y2) if guard => x2.toString; y2.toString
405
+ case (x3, y3) if guard => x3.toString; y3.toString
406
+ case (x4, y4) =>
407
+ getValue; x4.toString; y4.toString
408
+ }
409
+ }
410
+ }
411
+ object Test {
412
+ @lateasync def test() = new Foobar(0, 0).func(4)
413
+ }
414
+ """ )
415
+ }
416
+
389
417
def run (code : String ): Any = {
390
418
val reporter = new StoreReporter
391
419
val settings = new Settings (println(_))
392
- // settings.processArgumentString("-Xprint:patmat,postpatmat,jvm -Ybackend:GenASM -nowarn")
420
+ settings.processArgumentString(" -Xprint:patmat,postpatmat,jvm -nowarn" )
393
421
settings.outdir.value = sys.props(" java.io.tmpdir" )
394
422
settings.embeddedDefaults(getClass.getClassLoader)
395
423
val isInSBT = ! settings.classpath.isSetByUser
@@ -407,9 +435,9 @@ class LateExpansion {
407
435
408
436
val run = new Run
409
437
val source = newSourceFile(code)
410
- // TreeInterrogation .withDebug {
411
- run.compileSources(source :: Nil )
412
- // }
438
+ TreeInterrogationApp .withDebug {
439
+ run.compileSources(source :: Nil )
440
+ }
413
441
Assert .assertTrue(reporter.infos.mkString(" \n " ), ! reporter.hasErrors)
414
442
val loader = new URLClassLoader (Seq (new File (settings.outdir.value).toURI.toURL), global.getClass.getClassLoader)
415
443
val cls = loader.loadClass(" Test" )
@@ -418,6 +446,7 @@ class LateExpansion {
418
446
}
419
447
420
448
abstract class LatePlugin extends Plugin {
449
+
421
450
import global ._
422
451
423
452
override val components : List [PluginComponent ] = List (new PluginComponent with TypingTransformers {
@@ -434,16 +463,16 @@ abstract class LatePlugin extends Plugin {
434
463
super .transform(tree) match {
435
464
case ap@ Apply (fun, args) if fun.symbol.hasAnnotation(autoAwaitSym) =>
436
465
localTyper.typed(Apply (TypeApply (gen.mkAttributedRef(asyncIdSym.typeOfThis, awaitSym), TypeTree (ap.tpe) :: Nil ), ap :: Nil ))
437
- case sel@ Select (fun, _) if sel.symbol.hasAnnotation(autoAwaitSym) && ! (tree.tpe.isInstanceOf [MethodTypeApi ] || tree.tpe.isInstanceOf [PolyTypeApi ] ) =>
466
+ case sel@ Select (fun, _) if sel.symbol.hasAnnotation(autoAwaitSym) && ! (tree.tpe.isInstanceOf [MethodTypeApi ] || tree.tpe.isInstanceOf [PolyTypeApi ]) =>
438
467
localTyper.typed(Apply (TypeApply (gen.mkAttributedRef(asyncIdSym.typeOfThis, awaitSym), TypeTree (sel.tpe) :: Nil ), sel :: Nil ))
439
468
case dd : DefDef if dd.symbol.hasAnnotation(lateAsyncSym) => atOwner(dd.symbol) {
440
- deriveDefDef(dd){ rhs : Tree =>
469
+ deriveDefDef(dd) { rhs : Tree =>
441
470
val invoke = Apply (TypeApply (gen.mkAttributedRef(asyncIdSym.typeOfThis, asyncSym), TypeTree (rhs.tpe) :: Nil ), List (rhs))
442
471
localTyper.typed(atPos(dd.pos)(invoke))
443
472
}
444
473
}
445
474
case vd : ValDef if vd.symbol.hasAnnotation(lateAsyncSym) => atOwner(vd.symbol) {
446
- deriveValDef(vd){ rhs : Tree =>
475
+ deriveValDef(vd) { rhs : Tree =>
447
476
val invoke = Apply (TypeApply (gen.mkAttributedRef(asyncIdSym.typeOfThis, asyncSym), TypeTree (rhs.tpe) :: Nil ), List (rhs))
448
477
localTyper.typed(atPos(vd.pos)(invoke))
449
478
}
@@ -454,6 +483,7 @@ abstract class LatePlugin extends Plugin {
454
483
}
455
484
}
456
485
}
486
+
457
487
override def newPhase (prev : Phase ): Phase = new StdPhase (prev) {
458
488
override def apply (unit : CompilationUnit ): Unit = {
459
489
val translated = newTransformer(unit).transformUnit(unit)
0 commit comments