@@ -7,7 +7,6 @@ import org.junit.{Assert, 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,56 @@ 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+ @ 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+
2271 @ Test def test0 (): Unit = {
2372 val result = wrapAndRun(
2473 """
@@ -27,6 +76,7 @@ class LateExpansion {
2776 | """ .stripMargin)
2877 assertEquals(" foobar" , result)
2978 }
79+
3080 @ Test def testGuard (): Unit = {
3181 val result = wrapAndRun(
3282 """
@@ -143,6 +193,7 @@ class LateExpansion {
143193 |}
144194 | """ .stripMargin)
145195 }
196+
146197 @ Test def shadowing2 (): Unit = {
147198 val result = run(
148199 """
@@ -369,6 +420,7 @@ class LateExpansion {
369420 }
370421 """ )
371422 }
423+
372424 @ Test def testNegativeArraySizeExceptionFine1 (): Unit = {
373425 val result = run(
374426 """
@@ -389,18 +441,20 @@ class LateExpansion {
389441 }
390442 """ )
391443 }
444+
392445 private def createTempDir (): File = {
393446 val f = File .createTempFile(" output" , " " )
394447 f.delete()
395448 f.mkdirs()
396449 f
397450 }
451+
398452 def run (code : String ): Any = {
399- // settings.processArgumentString("-Xprint:patmat,postpatmat,jvm -Ybackend:GenASM -nowarn")
400453 val out = createTempDir()
401454 try {
402455 val reporter = new StoreReporter
403456 val settings = new Settings (println(_))
457+ // settings.processArgumentString("-Xprint:refchecks,patmat,postpatmat,jvm -nowarn")
404458 settings.outdir.value = out.getAbsolutePath
405459 settings.embeddedDefaults(getClass.getClassLoader)
406460 val isInSBT = ! settings.classpath.isSetByUser
@@ -432,6 +486,7 @@ class LateExpansion {
432486}
433487
434488abstract class LatePlugin extends Plugin {
489+
435490 import global ._
436491
437492 override val components : List [PluginComponent ] = List (new PluginComponent with TypingTransformers {
@@ -448,16 +503,16 @@ abstract class LatePlugin extends Plugin {
448503 super .transform(tree) match {
449504 case ap@ Apply (fun, args) if fun.symbol.hasAnnotation(autoAwaitSym) =>
450505 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 ]) =>
452507 localTyper.typed(Apply (TypeApply (gen.mkAttributedRef(asyncIdSym.typeOfThis, awaitSym), TypeTree (sel.tpe) :: Nil ), sel :: Nil ))
453508 case dd : DefDef if dd.symbol.hasAnnotation(lateAsyncSym) => atOwner(dd.symbol) {
454- deriveDefDef(dd){ rhs : Tree =>
509+ deriveDefDef(dd) { rhs : Tree =>
455510 val invoke = Apply (TypeApply (gen.mkAttributedRef(asyncIdSym.typeOfThis, asyncSym), TypeTree (rhs.tpe) :: Nil ), List (rhs))
456511 localTyper.typed(atPos(dd.pos)(invoke))
457512 }
458513 }
459514 case vd : ValDef if vd.symbol.hasAnnotation(lateAsyncSym) => atOwner(vd.symbol) {
460- deriveValDef(vd){ rhs : Tree =>
515+ deriveValDef(vd) { rhs : Tree =>
461516 val invoke = Apply (TypeApply (gen.mkAttributedRef(asyncIdSym.typeOfThis, asyncSym), TypeTree (rhs.tpe) :: Nil ), List (rhs))
462517 localTyper.typed(atPos(vd.pos)(invoke))
463518 }
@@ -468,6 +523,7 @@ abstract class LatePlugin extends Plugin {
468523 }
469524 }
470525 }
526+
471527 override def newPhase (prev : Phase ): Phase = new StdPhase (prev) {
472528 override def apply (unit : CompilationUnit ): Unit = {
473529 val translated = newTransformer(unit).transformUnit(unit)
@@ -476,7 +532,7 @@ abstract class LatePlugin extends Plugin {
476532 }
477533 }
478534
479- override val runsAfter : List [String ] = " patmat " :: Nil
535+ override val runsAfter : List [String ] = " refchecks " :: Nil
480536 override val phaseName : String = " postpatmat"
481537
482538 })
0 commit comments