Skip to content

Fix decision about whether to use a trait or class as the parent #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/scala/scala/async/internal/AsyncTransform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
62 changes: 38 additions & 24 deletions src/test/scala/scala/async/run/late/LateExpansion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -263,6 +264,7 @@ class LateExpansion {
}
}
}
object Test { @lateasync def test: Unit = TestGenericTypeBoundIssue.doStuff(new Bound) }
""".stripMargin)
}

Expand All @@ -281,6 +283,7 @@ class LateExpansion {
42 // type mismatch; found : AnyVal required: Int
}
}
object Test { @lateasync def test: Unit = new TestReturnExprIssue("").doStuff }
""".stripMargin)
}

Expand Down Expand Up @@ -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()
}
}
}

Expand Down