diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2017-10-13 09:19:20 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-13 09:19:20 +1000 |
commit | 7b547eb0d201d9c994c03fb0014ef09767ec6fc8 (patch) | |
tree | 83a643db07da2e478015f124951522dcec7d4bb6 | |
parent | cf07b65470bd544160fe6f8b82e1fc523c8c8b38 (diff) | |
parent | 103f3727cd6ab9f8edcc280b5a1ea096de9f48ba (diff) | |
download | scala-async-7b547eb0d201d9c994c03fb0014ef09767ec6fc8.tar.gz scala-async-7b547eb0d201d9c994c03fb0014ef09767ec6fc8.tar.bz2 scala-async-7b547eb0d201d9c994c03fb0014ef09767ec6fc8.zip |
Merge pull request #178 from retronym/tycon
Fix decision about whether to use a trait or class as the parent
-rw-r--r-- | src/main/scala/scala/async/internal/AsyncTransform.scala | 2 | ||||
-rw-r--r-- | src/test/scala/scala/async/run/late/LateExpansion.scala | 62 |
2 files changed, 39 insertions, 25 deletions
diff --git a/src/main/scala/scala/async/internal/AsyncTransform.scala b/src/main/scala/scala/async/internal/AsyncTransform.scala index 58f7f64..dc12cf8 100644 --- a/src/main/scala/scala/async/internal/AsyncTransform.scala +++ b/src/main/scala/scala/async/internal/AsyncTransform.scala @@ -50,7 +50,7 @@ trait AsyncTransform { } val customParents = futureSystemOps.stateMachineClassParents - val tycon = if (customParents.exists(!_.typeSymbol.asClass.isTrait)) { + val tycon = if (customParents.forall(_.typeSymbol.asClass.isTrait)) { // prefer extending a class to reduce the class file size of the state machine. symbolOf[scala.runtime.AbstractFunction1[Any, Any]] } else { diff --git a/src/test/scala/scala/async/run/late/LateExpansion.scala b/src/test/scala/scala/async/run/late/LateExpansion.scala index 2cc8073..e012df8 100644 --- a/src/test/scala/scala/async/run/late/LateExpansion.scala +++ b/src/test/scala/scala/async/run/late/LateExpansion.scala @@ -247,6 +247,7 @@ class LateExpansion { @Test def testGenericTypeBoundaryIssue(): Unit = { val result = run( """ + import scala.async.run.late.{autoawait,lateasync} trait InstrumentOfValue trait Security[T <: InstrumentOfValue] extends InstrumentOfValue @@ -263,6 +264,7 @@ class LateExpansion { } } } + object Test { @lateasync def test: Unit = TestGenericTypeBoundIssue.doStuff(new Bound) } """.stripMargin) } @@ -281,6 +283,7 @@ class LateExpansion { 42 // type mismatch; found : AnyVal required: Int } } + object Test { @lateasync def test: Unit = new TestReturnExprIssue("").doStuff } """.stripMargin) } @@ -386,34 +389,45 @@ class LateExpansion { } """) } + private def createTempDir(): File = { + val f = File.createTempFile("output", "") + f.delete() + f.mkdirs() + f + } def run(code: String): Any = { - val reporter = new StoreReporter - val settings = new Settings(println(_)) // settings.processArgumentString("-Xprint:patmat,postpatmat,jvm -Ybackend:GenASM -nowarn") - settings.outdir.value = sys.props("java.io.tmpdir") - settings.embeddedDefaults(getClass.getClassLoader) - val isInSBT = !settings.classpath.isSetByUser - if (isInSBT) settings.usejavacp.value = true - val global = new Global(settings, reporter) { - self => - - object late extends { - val global: self.type = self - } with LatePlugin - - override protected def loadPlugins(): List[Plugin] = late :: Nil - } - import global._ + val out = createTempDir() + try { + val reporter = new StoreReporter + val settings = new Settings(println(_)) + settings.outdir.value = out.getAbsolutePath + settings.embeddedDefaults(getClass.getClassLoader) + val isInSBT = !settings.classpath.isSetByUser + if (isInSBT) settings.usejavacp.value = true + val global = new Global(settings, reporter) { + self => + + object late extends { + val global: self.type = self + } with LatePlugin + + override protected def loadPlugins(): List[Plugin] = late :: Nil + } + import global._ - val run = new Run - val source = newSourceFile(code) -// TreeInterrogation.withDebug { + val run = new Run + val source = newSourceFile(code) + // TreeInterrogation.withDebug { run.compileSources(source :: Nil) -// } - Assert.assertTrue(reporter.infos.mkString("\n"), !reporter.hasErrors) - val loader = new URLClassLoader(Seq(new File(settings.outdir.value).toURI.toURL), global.getClass.getClassLoader) - val cls = loader.loadClass("Test") - cls.getMethod("test").invoke(null) + // } + Assert.assertTrue(reporter.infos.mkString("\n"), !reporter.hasErrors) + val loader = new URLClassLoader(Seq(new File(settings.outdir.value).toURI.toURL), global.getClass.getClassLoader) + val cls = loader.loadClass("Test") + cls.getMethod("test").invoke(null) + } finally { + scala.reflect.io.Path.apply(out).deleteRecursively() + } } } |