Skip to content

Fix ownership corruption problem in the awaited expression #210

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 1 commit into from
Feb 8, 2019
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/AnfTransform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private[async] trait AnfTransform {

case ValDef(mods, name, tpt, rhs) =>
if (containsAwait(rhs)) {
val stats :+ expr = api.atOwner(api.currentOwner.owner)(linearize.transformToList(rhs))
val stats :+ expr = linearize.transformToList(rhs)
stats.foreach(_.changeOwner(api.currentOwner, api.currentOwner.owner))
stats :+ treeCopy.ValDef(tree, mods, name, tpt, expr)
} else List(tree)
Expand Down
52 changes: 51 additions & 1 deletion src/test/scala/scala/async/run/late/LateExpansion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,56 @@ class LateExpansion {
""")
}

@Test def testByNameOwner(): Unit = {
val result = run(
"""
import scala.async.run.late.{autoawait,lateasync}
object Bleh {
@autoawait @lateasync def asyncCall(): Int = 0
def byName[T](fn: => T): T = fn
}
object Boffo {
@autoawait @lateasync def jerk(): Unit = {
val pointlessSymbolOwner = 1 match {
case _ =>
Bleh.asyncCall()
Bleh.byName {
val whyDoHateMe = 1
whyDoHateMe
}
}
}
}
object Test {
@lateasync def test() = Boffo.jerk()
}
""")
}

@Test def testByNameOwner2(): Unit = {
val result = run(
"""
import scala.async.run.late.{autoawait,lateasync}
object Bleh {
@autoawait @lateasync def bleh = Bleh
def byName[T](fn: => T): T = fn
}
object Boffo {
@autoawait @lateasync def slob(): Unit = {
val pointlessSymbolOwner = {
Bleh.bleh.byName {
val whyDoHateMeToo = 1
whyDoHateMeToo
}
}
}
}
object Test {
@lateasync def test() = Boffo.slob()
}
""")
}

private def createTempDir(): File = {
val f = File.createTempFile("output", "")
f.delete()
Expand All @@ -455,9 +505,9 @@ class LateExpansion {
try {
val reporter = new StoreReporter
val settings = new Settings(println(_))
//settings.processArgumentString("-Xprint:refchecks,patmat,postpatmat,jvm -nowarn")
settings.outdir.value = out.getAbsolutePath
settings.embeddedDefaults(getClass.getClassLoader)
// settings.processArgumentString("-Xprint:patmat,postpatmat,jvm -nowarn")
val isInSBT = !settings.classpath.isSetByUser
if (isInSBT) settings.usejavacp.value = true
val global = new Global(settings, reporter) {
Expand Down