Skip to content

Compatibility with Scala 2.12.0-RC1 #160

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 2 commits into from
Sep 8, 2016
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
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ env:
script:
- admin/build.sh
scala:
- 2.11.4
- 2.11.8
- 2.12.0-RC1 # !!! Duplicated below, edit with care
jdk:
- openjdk6
- openjdk7
- oraclejdk8
matrix:
exclude:

- scala: 2.12.0-RC1 # !!! Duplicated above, edit with care
jdk: openjdk6
notifications:
email:
- [email protected]
Expand Down
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
scalaVersion := "2.11.6"
crossScalaVersions := List("2.11.8", "2.12.0-RC1")

scalaVersion := crossScalaVersions.value.head

// Uncomment to test with a locally built copy of Scala.
// scalaHome := Some(file("/code/scala2/build/pack"))
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/scala/async/internal/AnfTransform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private[async] trait AnfTransform {
def transformToBlock(tree: Tree): Block = listToBlock(transformToList(tree))

def _transformToList(tree: Tree): List[Tree] = trace(tree) {
val stats :+ expr = anf.transformToList(tree)
val stats :+ expr = _anf.transformToList(tree)
def statsExprUnit =
stats :+ expr :+ api.typecheck(atPos(expr.pos)(Literal(Constant(()))))
def statsExprThrow =
Expand Down Expand Up @@ -163,7 +163,7 @@ private[async] trait AnfTransform {
internal.valDef(sym, internal.changeOwner(lhs, api.currentOwner, sym)).setType(NoType).setPos(pos)
}

object anf {
object _anf {
def transformToList(tree: Tree): List[Tree] = {
mode = Anf; blockToList(api.recur(tree))
}
Expand Down Expand Up @@ -385,7 +385,7 @@ private[async] trait AnfTransform {

def anfLinearize(tree: Tree): Block = {
val trees: List[Tree] = mode match {
case Anf => anf._transformToList(tree)
case Anf => _anf._transformToList(tree)
case Linearizing => linearize._transformToList(tree)
}
listToBlock(trees)
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/scala/async/internal/AsyncAnalysis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ trait AsyncAnalysis {
c.abort(tree.pos, "return is illegal within a async block")
case DefDef(mods, _, _, _, _, _) if mods.hasFlag(Flag.LAZY) && containsAwait(tree) =>
reportUnsupportedAwait(tree, "lazy val initializer")
case ValDef(mods, _, _, _) if mods.hasFlag(Flag.LAZY) && containsAwait(tree) =>
reportUnsupportedAwait(tree, "lazy val initializer")
case CaseDef(_, guard, _) if guard exists isAwait =>
// TODO lift this restriction
reportUnsupportedAwait(tree, "pattern guard")
Expand Down
11 changes: 7 additions & 4 deletions src/main/scala/scala/async/internal/AsyncTransform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,13 @@ trait AsyncTransform {
case ValDef(_, _, _, rhs) if liftedSyms(tree.symbol) =>
api.atOwner(api.currentOwner) {
val fieldSym = tree.symbol
val lhs = atPos(tree.pos) {
gen.mkAttributedStableRef(thisType(fieldSym.owner.asClass), fieldSym)
if (fieldSym.asTerm.isLazy) Literal(Constant(()))
else {
val lhs = atPos(tree.pos) {
gen.mkAttributedStableRef(thisType(fieldSym.owner.asClass), fieldSym)
}
treeCopy.Assign(tree, lhs, api.recur(rhs)).setType(definitions.UnitTpe).changeOwner(fieldSym, api.currentOwner)
}
treeCopy.Assign(tree, lhs, api.recur(rhs)).setType(definitions.UnitTpe).changeOwner(fieldSym, api.currentOwner)
}
case _: DefTree if liftedSyms(tree.symbol) =>
EmptyTree
Expand All @@ -176,7 +179,7 @@ trait AsyncTransform {
}

val liftablesUseFields = liftables.map {
case vd: ValDef => vd
case vd: ValDef if !vd.symbol.asTerm.isLazy => vd
case x => typingTransform(x, stateMachineClass)(useFields)
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/scala/async/internal/Lifter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ trait Lifter {

// Only mark transitive references of defs, modules and classes. The RHS of lifted vals/vars
// stays in its original location, so things that it refers to need not be lifted.
if (!(sym.isTerm && (sym.asTerm.isVal || sym.asTerm.isVar)))
if (!(sym.isTerm && !sym.asTerm.isLazy && (sym.asTerm.isVal || sym.asTerm.isVar)))
defSymToReferenced(sym).foreach(sym2 => markForLift(sym2))
}
}
Expand All @@ -117,7 +117,8 @@ trait Lifter {
sym.setFlag(MUTABLE | STABLE | PRIVATE | LOCAL)
sym.setName(name.fresh(sym.name.toTermName))
sym.setInfo(deconst(sym.info))
treeCopy.ValDef(vd, Modifiers(sym.flags), sym.name, TypeTree(tpe(sym)).setPos(t.pos), EmptyTree)
val rhs1 = if (sym.asTerm.isLazy) rhs else EmptyTree
treeCopy.ValDef(vd, Modifiers(sym.flags), sym.name, TypeTree(tpe(sym)).setPos(t.pos), rhs1)
case dd@DefDef(_, _, tparams, vparamss, tpt, rhs) =>
sym.setName(this.name.fresh(sym.name.toTermName))
sym.setFlag(PRIVATE | LOCAL)
Expand Down
8 changes: 8 additions & 0 deletions src/main/scala/scala/async/internal/TransformUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,14 @@ private[async] trait TransformUtils {
typingTransform(t, owner) {
(tree, api) =>
tree match {
case LabelDef(name, params, rhs) =>
val rhs1 = api.recur(rhs)
if (rhs1.tpe =:= UnitTpe) {
internal.setInfo(tree.symbol, internal.methodType(tree.symbol.info.paramLists.head, UnitTpe))
treeCopy.LabelDef(tree, name, params, rhs1)
} else {
treeCopy.LabelDef(tree, name, params, rhs1)
}
case Block(stats, expr) =>
val stats1 = stats map api.recur
val expr1 = api.recur(expr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ class LiveVariablesSpec {

// https://github.com/scala/async/issues/104
@Test def dontNullOutVarsOfTypeNothing_t104(): Unit = {
implicit val ec: scala.concurrent.ExecutionContext = null
import scala.async.Async._
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, Future}
Expand Down