@@ -3,11 +3,10 @@ package scala.async.run.late
33import java .io .File
44
55import junit .framework .Assert .assertEquals
6- import org .junit .{Assert , Test }
6+ import org .junit .{Assert , Ignore , Test }
77
88import scala .annotation .StaticAnnotation
99import scala .annotation .meta .{field , getter }
10- import scala .async .TreeInterrogation
1110import scala .async .internal .AsyncId
1211import scala .reflect .internal .util .ScalaClassLoader .URLClassLoader
1312import scala .tools .nsc ._
@@ -19,6 +18,57 @@ import scala.tools.nsc.transform.TypingTransformers
1918// calls it from a new phase that runs after patmat.
2019class LateExpansion {
2120
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+
2272 @ Test def test0 (): Unit = {
2373 val result = wrapAndRun(
2474 """
@@ -27,6 +77,7 @@ class LateExpansion {
2777 | """ .stripMargin)
2878 assertEquals(" foobar" , result)
2979 }
80+
3081 @ Test def testGuard (): Unit = {
3182 val result = wrapAndRun(
3283 """
@@ -143,6 +194,7 @@ class LateExpansion {
143194 |}
144195 | """ .stripMargin)
145196 }
197+
146198 @ Test def shadowing2 (): Unit = {
147199 val result = run(
148200 """
@@ -369,6 +421,7 @@ class LateExpansion {
369421 }
370422 """ )
371423 }
424+
372425 @ Test def testNegativeArraySizeExceptionFine1 (): Unit = {
373426 val result = run(
374427 """
@@ -389,18 +442,20 @@ class LateExpansion {
389442 }
390443 """ )
391444 }
445+
392446 private def createTempDir (): File = {
393447 val f = File .createTempFile(" output" , " " )
394448 f.delete()
395449 f.mkdirs()
396450 f
397451 }
452+
398453 def run (code : String ): Any = {
399- // settings.processArgumentString("-Xprint:patmat,postpatmat,jvm -Ybackend:GenASM -nowarn")
400454 val out = createTempDir()
401455 try {
402456 val reporter = new StoreReporter
403457 val settings = new Settings (println(_))
458+ // settings.processArgumentString("-Xprint:refchecks,patmat,postpatmat,jvm -nowarn")
404459 settings.outdir.value = out.getAbsolutePath
405460 settings.embeddedDefaults(getClass.getClassLoader)
406461 val isInSBT = ! settings.classpath.isSetByUser
@@ -432,6 +487,7 @@ class LateExpansion {
432487}
433488
434489abstract class LatePlugin extends Plugin {
490+
435491 import global ._
436492
437493 override val components : List [PluginComponent ] = List (new PluginComponent with TypingTransformers {
@@ -448,16 +504,16 @@ abstract class LatePlugin extends Plugin {
448504 super .transform(tree) match {
449505 case ap@ Apply (fun, args) if fun.symbol.hasAnnotation(autoAwaitSym) =>
450506 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 ]) =>
452508 localTyper.typed(Apply (TypeApply (gen.mkAttributedRef(asyncIdSym.typeOfThis, awaitSym), TypeTree (sel.tpe) :: Nil ), sel :: Nil ))
453509 case dd : DefDef if dd.symbol.hasAnnotation(lateAsyncSym) => atOwner(dd.symbol) {
454- deriveDefDef(dd){ rhs : Tree =>
510+ deriveDefDef(dd) { rhs : Tree =>
455511 val invoke = Apply (TypeApply (gen.mkAttributedRef(asyncIdSym.typeOfThis, asyncSym), TypeTree (rhs.tpe) :: Nil ), List (rhs))
456512 localTyper.typed(atPos(dd.pos)(invoke))
457513 }
458514 }
459515 case vd : ValDef if vd.symbol.hasAnnotation(lateAsyncSym) => atOwner(vd.symbol) {
460- deriveValDef(vd){ rhs : Tree =>
516+ deriveValDef(vd) { rhs : Tree =>
461517 val invoke = Apply (TypeApply (gen.mkAttributedRef(asyncIdSym.typeOfThis, asyncSym), TypeTree (rhs.tpe) :: Nil ), List (rhs))
462518 localTyper.typed(atPos(vd.pos)(invoke))
463519 }
@@ -468,6 +524,7 @@ abstract class LatePlugin extends Plugin {
468524 }
469525 }
470526 }
527+
471528 override def newPhase (prev : Phase ): Phase = new StdPhase (prev) {
472529 override def apply (unit : CompilationUnit ): Unit = {
473530 val translated = newTransformer(unit).transformUnit(unit)
@@ -476,7 +533,7 @@ abstract class LatePlugin extends Plugin {
476533 }
477534 }
478535
479- override val runsAfter : List [String ] = " patmat " :: Nil
536+ override val runsAfter : List [String ] = " refchecks " :: Nil
480537 override val phaseName : String = " postpatmat"
481538
482539 })
0 commit comments