From 04b9a04ce5b4155fc7b83799e83136cf4d77c25f Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Fri, 13 Oct 2017 08:41:40 +1000 Subject: Fix decision about whether to use a trait or class as the parent --- src/main/scala/scala/async/internal/AsyncTransform.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 { -- cgit v1.2.3 From 119d73381cb033f1a27a25d7d8730a58be9c7066 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Fri, 13 Oct 2017 08:50:13 +1000 Subject: Add diagnostic for intermittently failing test --- src/test/scala/scala/async/run/late/LateExpansion.scala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/scala/scala/async/run/late/LateExpansion.scala b/src/test/scala/scala/async/run/late/LateExpansion.scala index 2cc8073..8ac8aec 100644 --- a/src/test/scala/scala/async/run/late/LateExpansion.scala +++ b/src/test/scala/scala/async/run/late/LateExpansion.scala @@ -412,7 +412,12 @@ class LateExpansion { // } 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") + val cls = try { + loader.loadClass("Test") + } catch { + case ex: ClassNotFoundException => + throw new ClassNotFoundException(new File(settings.outdir.value).list().mkString(", "), ex) + } cls.getMethod("test").invoke(null) } } -- cgit v1.2.3 From 103f3727cd6ab9f8edcc280b5a1ea096de9f48ba Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Fri, 13 Oct 2017 09:16:02 +1000 Subject: Fix race condition in tests and make some tests actually run --- .../scala/scala/async/run/late/LateExpansion.scala | 65 ++++++++++++---------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/src/test/scala/scala/async/run/late/LateExpansion.scala b/src/test/scala/scala/async/run/late/LateExpansion.scala index 8ac8aec..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,39 +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 = try { - loader.loadClass("Test") - } catch { - case ex: ClassNotFoundException => - throw new ClassNotFoundException(new File(settings.outdir.value).list().mkString(", "), ex) + // } + 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() } - cls.getMethod("test").invoke(null) } } -- cgit v1.2.3